import matplotlib.pyplot as plt
import numpy as np
plt.rcParams['font.sans-serif'] = ['SimHei']#正常显示中文标签
plt.rcParams['axes.unicode_minus'] = False#正常显示负号
x = [1,5,2]
plt.pie(x)
plt.pie(x,labels = ['apple','orange','banana'])
plt.pie(x,labels = ['apple','orange','banana'],explode =[0.1,1,0])#分离
plt.pie(x,labels = ['apple','orange','banana'],startangle =130)#x轴逆时针
plt.pie(x,labels = ['apple','orange','banana'],shadow =True)#影子
plt.pie(x,labels = ['apple','orange','banana'],shadow =True,labeldistance = 0.5)#到圆心的距离
plt.pie(x,labels = ['apple','orange','banana'],shadow =True,labeldistance = 1.1,autopct = '%1.1f')#数字
plt.pie(x,labels = ['apple','orange','banana'],shadow =True,labeldistance = 1.1,autopct = '%1.1f%%')#数字
plt.pie(x,labels = ['apple','orange','banana'],shadow =True,labeldistance = 1.1,autopct = '%1.1f',pctdistance=0.5)#数字位置
plt.pie(x,labels=['apple','orange','banana'],radius = 2)#饼图大小
plt.pie(x,labels=['apple','orange','banana'],frame = True)#
plt.xlim(-1,1)
plt.ylim(-1,1)
plt.grid()
plt.pie(x,labels=['apple','orange','banana'],textprops = {'fontsize':20,'color':'blue'})
plt.axis('equal')#饼图显示为正的图
plt.legend()
#圆环图
plt.pie(x,labels = ['apple','orange','banana'])
plt.pie([1],colors = 'w',radius=0.7)
#内嵌环形饼图
plt.figure(dpi = 60)
elements = [‘面粉’,‘砂糖’,‘奶油’,‘果酱’,‘坚果’]
a = [0.4,0.15,0.2,1,0.15]
b = [0.1,0.2,0.3,0.15,0.25]
plt.pie(a,labels = elements)
plt.pie(b,radius=0.6,labels = elements)
plt.pie([1],colors = ‘w’,radius=0.3)
plt.legend(loc = 1)
data = [np.random.normal(0,std,100) for std in range(1,4)]
plt.boxplot(data)
plt.boxplot(data,notch = True)
plt.boxplot(data,notch = True,sym = ‘’)#异常点形状
plt.boxplot(data,notch = True,sym = '’,vert = False)#横向
plt.boxplot(data,notch = True,sym = ‘*’,vert = False,patch_artist=True)#是否填充箱体颜色
a = np.random.randn(50)
b = np.random.randn(50)
plt.scatter(a,b,s =np.power(10a+20b,2),c = np.random.rand(50),cmap = plt.cm.RdYlBu)
#棉棒图
x = np.linspace(0.5,2*np.pi,20)
y = np.random.randn(20)
plt.stem(x,y)
plt.stem(x,y,linefmt = '-.')#棉棒形状
plt.stem(x,y,linefmt = '-.',markerfmt = 's')#棉棒末端形状
plt.stem(x,y,linefmt = '-.',markerfmt = 's',basefmt = '--')
plt.stem(x,y,linefmt = '-.',markerfmt = 's',basefmt = '--',bottom = 1)
#误差棒图
x = np.linspace(-4,4,10)
y = np.sin(x)
plt.errorbar(x,y,yerr = 0.2,xerr = 0.2)
plt.errorbar(x,y,yerr = 0.2,xerr = 0.2,fmt = 'ro:')#数据点标记样式和数据点标记的连接样式
plt.errorbar(x,y,yerr = 0.2,xerr = 0.2,fmt = 'ro:',ecolor = 'g')#误差棒颜色
plt.errorbar(x,y,yerr = 0.2,xerr = 0.2,fmt = 'ro:',ecolor = 'g',ms = 10)
plt.errorbar(x,y,yerr = 0.2,xerr = 0.2,fmt = 'ro:',ecolor = 'g',ms = 10,mfc = 'orange',mec = 'black',capsize = 10)#数据点的颜色,数据点边缘颜色,误差棒边界横杠的大小,误差棒边界横杠的厚度
#加误差棒的柱状图
x = np.arange(5)
y = [66,88,55,99,123]
err = [5,9,6,10,7]
err_attri = dict(elinewidth = 2,ecolor ='black',capsize = 3)
plt.bar(x,y,color ='b',width = 0.6,align = 'center',yerr = err,error_kw = err_attri)
ax1 = plt.subplot2grid((3,3),(0,0))
ax2 = plt.subplot2grid((3,3),(1,0))
ax3 = plt.subplot2grid((3,3),(0,2),rowspan = 3)
ax4 = plt.subplot2grid((3,3),(2,0),colspan = 2)
ax5 = plt.subplot2grid((3,3),(0,1),rowspan = 2)