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')

11 python数据可视化(统计图)的图1

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')
11 python数据可视化(统计图)的图2

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')

11 python数据可视化(统计图)的图3

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)

11 python数据可视化(统计图)的图4

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')

11 python数据可视化(统计图)的图5

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='*')

11 python数据可视化(统计图)的图6

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:')

11 python数据可视化(统计图)的图7

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')

11 python数据可视化(统计图)的图8

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)

11 python数据可视化(统计图)的图9

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)

11 python数据可视化(统计图)的图10

登录后免费查看全文
立即登录
默认 最新
当前暂无评论,小编等你评论哦!
点赞 17 评论 收藏
关注