本文只做简单概述,总结来自:菜鸟教程 https://www.runoob.com/w3cnote/matplotlib-tutorial.html
简单的绘图,了解流程,看代码,结果如图:
import numpy as np
import matplotlib.pyplot as plt
X = np.linspace(-np.pi, np.pi, 256, endpoint=True)
C,S = np.cos(X), np.sin(X)
plt.plot(X,C)
plt.plot(X,S)
plt.show()
from pylab import *
scatter(X,Y) #画散点
bar(x,height)#画柱子,x坐标,柱子高度
text(x,y,string)#写字,坐标x,y, string写的字
ylim(bottom,top)#限制y轴显示 xlim同理
imshow(img)#画图像
pie([0.1,0.2,0.5]) #饼状图
3D图
from pylab import *
from mpl_toolkits.mplot3d import Axes3D
fig = figure()
ax = Axes3D(fig)
X = np.arange(-4, 4, 0.25)
Y = np.arange(-4, 4, 0.25)
X, Y = np.meshgrid(X, Y)
R = np.sqrt(X**2 + Y**2)
Z = np.sin(R)
ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap='hot')
show()