程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python draws a tree view

編輯:Python
import matplotlib.pyplot as plt
import squarify
my_dpi=96
plt.figure(figsize=(480/my_dpi, 480/my_dpi), dpi=my_dpi)
squarify.plot(sizes=[13,22,35,5], label=["group A", "group B", "group C", "group D"], alpha=.7 )
plt.axis('off')
plt.show()

import matplotlib.pyplot as plt
import squarify
import pandas as pd
df = pd.DataFrame({'nb_people':[8,3,4,2], 'group':["group A", "group B", "group C", "group D"] })
my_dpi=96
plt.figure(figsize=(480/my_dpi, 480/my_dpi), dpi=my_dpi)
squarify.plot(sizes=df['nb_people'], label=df['group'], alpha=.8 )
plt.axis('off')
plt.show()

 

import matplotlib.pyplot as plt
import squarify
import pandas as pd
my_dpi=96
plt.figure(figsize=(480/my_dpi, 480/my_dpi), dpi=my_dpi)
squarify.plot(sizes=[13,22,35,5], label=["group A", "group B", "group C", "group D"], color=["red","green","blue", "grey"], alpha=.4 )
plt.axis('off')
plt.show()

 

import matplotlib
import matplotlib.pyplot as plt
import pandas as pd
import squarify
my_dpi=96
plt.figure(figsize=(480/my_dpi, 480/my_dpi), dpi=my_dpi)
my_values=[i**3 for i in range(1,100)]
cmap = matplotlib.cm.Blues
mini=min(my_values)
maxi=max(my_values)
norm = matplotlib.colors.Normalize(vmin=mini, vmax=maxi)
colors = [cmap(norm(value)) for value in my_values]
squarify.plot(sizes=my_values, alpha=.8, color=colors )
plt.axis('off')
plt.show()

 

 

import matplotlib
import matplotlib.pyplot as plt
import pandas as pd
import squarify
import pandas as pd
df = pd.DataFrame({
'group':["group A", "group A", "group A", "group A", "group B", "group B", "group C", "group C", "group C"],
'subgroup':[1,2,3,4,1,2,1,2,3],
'value':[13,5,22,12,11,7,3,1,23]
})
mycolors=list()
all_pal=[matplotlib.cm.Blues, matplotlib.cm.Greens, matplotlib.cm.Oranges]
num=-1
for i in df.group.unique():
num+=1
cmap = all_pal[num]
tmp=df[df.group==i]
mini=min(tmp.value)
maxi=max(tmp.value)
norm = matplotlib.colors.Normalize(vmin=mini-12, vmax=maxi+12)
colors = [cmap(norm(value)) for value in tmp.value]
mycolors=mycolors+colors
squarify.plot(sizes=df['value'], alpha=.8, color=mycolors )
plt.axis('off')
plt.show()

The blogger opened a new official account ,  I hope you can scan the code and pay attention , Thank you very much .

 

This article is from :https://github.com/holtzy/The-Python-Graph-Gallery/blob/master/PGG_notebook.py 


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved