函数 | 含义 |
---|---|
plt.plot(x,y,fmt,…) | 绘制坐标图 |
plt.boxplot(data,notch,position) | 绘制箱形图 |
plt.bar(left,height,width,bottom) | 绘制条形图 |
plt.barh(width,bottom,left,height) | 绘制横向条形图 |
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长度相同 |
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() | 绘制数据日期 |
示例
#pie.py
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.2f%%',
shadow=False,
startangle=90)
plt.axis('equal')
plt.show()
示例
import numpy as np
import matplotlib.pyplot as plt
np.random.seed(0)
mu, sigma = 100, 20
a = np.random.normal(mu, sigma, size=100) #符合正态分布的数组
plt.hist(a, 40,histtype='stepfilled', facecolor='b', alpha=0.75)
plt.title('Histogram')
plt.show()
import numpy as np
import matplotlib.pyplot as plt
N = 20
theta = np.linspace(0, 2 * np.pi, N, endpoint=False)
radii = 10 * np.random.rand(N)
width = np.pi / 2 * np.random.rand(N)
ax = plt.subplot(111, projection='polar')
#bar里的三个数组分为代表极坐标所处角度、覆盖宽度和高度
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()
示例
#Scatter.py
import numpy as np
import matplotlib.pyplot as plt
fig,ax=plt.subplots()
ax.plot(10*np.random.randn(100),10*np.random.randn(100),'o')
ax.set_title('Simple Scatter')
plt.show()