python中的matplotlib库图表绘制

python中的matplotlib库图表绘制


函数 含义
plt.plot(x,y,fmt,…) 绘制一个坐标图
plt.boxplot(data,notch,position) 绘制一个箱形图
plt.bar(left,height,width,bottom) 绘制一个条形图
plt.barh(width,bottom,left,height) 绘制一个横向条形图
plt.step(x,y,where) 绘制步阶图
plt.hist(x,bins,normed) 绘制直方图
plt.contour(X,Y,Z,N) 绘制等值图
plt.vlines() 绘制垂直图
plt.stem(x,y,linefmt,markerfmt) 绘制柴火图
plt.plot_date() 绘制数据日期
plt.polar(theta, r) 绘制极坐标图
plt.pie(data, explode) 绘制饼图
plt.psd(x,NFFT=256,pad_to,Fs) 绘制功率谱密度图
plt.specgram(x,NFFT=256,pad_to,F) 绘制谱图
plt.cohere(x,y,NFFT=256,Fs) 绘制X‐Y的相关性函数
plt.scatter(x,y) 绘制散点图,其中,x和y长度相同

1.坐标图

# 1.坐标图
a =  np.arange(0,5,0.1)
def func(t):
   return np.exp(t)

plt.plot(a,func(a))
plt.show()

在这里插入图片描述

2.饼图

# 2.饼图
labels = 'C/C++','JAVA','Python','R','PHP'
sizes = [23,25,23,15,14]  # 随便写的数据
plt.pie(sizes,labels=labels,autopct='%1.1f%%',shadow=False,startangle=90)
plt.show()

在这里插入图片描述

3.直方图

# 3.直方图
np.random.seed(1)
# 均值 ,标准差
arv , sigma = 100 ,20
a = np.random.normal(arv,sigma ,size=100)
plt.subplot(211)
plt.hist(a,20,normed=1,histtype='stepfilled',facecolor='c',alpha=0.75)
plt.title('Histogram')

plt.subplot(212)
plt.hist(a,40,normed=1,histtype='stepfilled',facecolor='c',alpha=0.75)
plt.title('Histogram')
# 将20改为40 为修改直方图数量
plt.show()

在这里插入图片描述

4.极坐标图

# 4.极坐标
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.散点图

# 5.散点图
fig,ax = plt.subplots()
a = 10* np.random.randn(100)
b = 10*np.random.rand(100)
ax.plot(a, b,'o')
plt.show()

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_41179709/article/details/84785497