11 python数据可视化(统计图)
00 载入扩展库
import numpy as np
import matplotlib.pyplot as plt
01 plt.bar(x,y,width,align,hatch,color,ec,fc,ls,lw,)
x=np.array([1,2,3,4,5,6])
y=np.array([3,1,4,5,8,9])
plt.bar(x,y,width=0.5,align='edge',ec='r',fc='b',ls='-.',lw='3',hatch='//')
plt.xticks(x,('q','a','c','e','r','j'),size=20,weight='heavy')
02 plt.barh(x,y,height,align,hatch,color,ec,fc,ls,lw,)
x=np.array([1,2,3,4,5,6])
y=np.array([3,1,4,5,8,9])
plt.barh(x,y,height=0.5,align='center',ec='r',fc='b',ls='-.',lw='3',hatch='//')
plt.yticks(x,('q','a','c','e','r','j'),size=20,weight='heavy')
03 plt.hist(x,bins,align,density,rwidth)
x=np.random.randint(0,11,100)
bins=np.arange(0,12,1)
plt.hist(x,bins,align='left',density=True,rwidth=0.5,ec='r',fc='g')
04 plt.pie(x,autopct,explode,labels,startangle,shadow)
x=[15.33, 30, 44.67, 10]
label=['Frogs', 'Hogs', 'Dogs', 'Logs']
explode = [0, 0.1, 0, 0]
plt.pie(x,autopct='%.2f%%',explode=explode, labels=label,startangle=45)
05 plt.polar(theta,r,c,ls,lw,marker,ms,mfc.mec,mew)
theta=np.random.rand(10)*2*np.pi
r=np.random.rand(10)*10
plt.polar(theta,r,c='b',ls='-.',lw=1,marker='*',ms=10,mfc='r')
06 plt.scatter(x,y,s,c,marker,edgecolor,facecolor,linewidth,linestyle)
x = np.random.rand(30)
y = np.random.rand(30)
colors = np.random.rand(30)
area = (30 * np.random.rand(30))**2
plt.scatter(x, y, s=area, c=colors,marker='*')
07 plt.stem(x,y,markerfmt,basefmt,linfmt)
x=np.linspace(1,6,20)
y=np.random.randn(20)
plt.stem(x,y,markerfmt='rx',basefmt='b-.',linefmt='k:')
08 plt.boxplot(x)
x=np.random.rand(1000)*10
y=np.random.rand(1000)*15
plt.boxplot([x,y])
plt.grid(axis='y',ls=':',c='b')
09 plt.errorbar(x,y,c,ls,lw,marker,ms,mec,mfc,mew)
x = np.arange(8)
y = 2.5 * np.sin(x / 20 * np.pi)
yerr=0.2
plt.errorbar(x,y,yerr,ls='-.',c='k',marker='x',ms=20)
x = np.arange(8)
y = 2.5 * np.sin(x / 20 * np.pi)
yerr=[0.2,0.1,0.3,0.1,0.5,0.1,0.6,0.1]
uplims=[True,False]*4
lolims=[False,True]*4
plt.errorbar(x,y,yerr=yerr,uplims=uplims,lolims=lolims)