5.Matplotlib基礎繪圖函式
阿新 • • 發佈:2018-12-30
1.概述
2.pyplot餅圖的繪製
import matplotlib.pyplot as plt labels ='Frogs','Hogs','Dogs','Logs' sizes =[15,30,45,10] explode=(0,0.1,0,0) plt.pie(sizes,explode=explode,labels=labels,autopct='%1.1f%%', shadow=False,startangle=90) plt.show()
import matplotlib.pyplot as plt labels ='Frogs','Hogs','Dogs','Logs' sizes =[15,30,45,10] explode=(0,0.1,0,0) plt.pie(sizes,explode=explode,labels=labels,autopct='%1.1f%%', shadow=False,startangle=90) plt.axis('equal') plt.show()
3.pyplot直方圖的繪製
import matplotlib.pyplot as plt import numpy as np np.random.seed(0) mu,sigma =100,20 #均值和標準差 a =np.random.normal(mu,sigma,size =100) plt.hist(a,20,normed=1,histtype='stepfilled', facecolor ='b',alpha=0.75) plt.title('Histogram') plt.show()
4.pyplot極座標的繪製
import matplotlib.pyplot as plt import numpy as np N=20 theta =np.linspace(0.0,2*np.pi,N,endpoint=False) radii=10*np.random.rand(N) width =np.pi/4*np.random.rand(N) ax=plt.subplot(111,projection='polar') bars =ax.bar(theta,radii,width=width,bottom=0.0) for r,bar in zip(radii,bars): bar.set_facecolor(plt.cm.viridis(r/10.)) bar.set_alpha(0.5) plt.show()
5.pyplot散點圖的繪製
import matplotlib.pyplot as plt import numpy as np fig,ax =plt.subplots() ax.plot(10*np.random.rand(100), 10*np.random.randn(100),'o') ax.set_title('Simple Scatter') plt.show()