平面图绘制
from matplotlib import pyplot as plt
import numpy as np
x = np.linspace(-np.pi,np.pi)
plt.plot(x,np.cos(x),color='red')
plt.show()
x = np.linspace(0,2*np.pi,50)
plt.plot(x,np.sin(x),'c:' ,
x,np.sin(x-np.pi/2),'b-.')
plt.show()
x = np.random.randn(20)
y = np.random.randn(20)
x1 = np.random.randn(40)
y1 = np.random.randn(40)
plt.scatter(x,y,s=50,color='b',marker='<',label='S1')
plt.scatter(x1,y1,s=50,color='y',marker='o',alpha=0.2,label='S2')
plt.grid(True)
plt.xlabel('x axis')
plt.ylabel('y axis')
plt.legend()
plt.title('My Scatter')
plt.show()
x = np.linspace(0,2*np.pi,50)
plt.subplot(2,2,1)
plt.plot(x,np.sin(x),'b',label='sin(x)')
plt.legend()
plt.subplot(2,2,2)
plt.plot(x,np.cos(x),'r',label='cos(x)')
plt.legend()
plt.subplot(2,2,3)
plt.plot(x,np.exp(x),'k',label='exp(x)')
plt.legend()
plt.subplot(2,2,4)
plt.plot(x,np.arctan(x),'y',label='arctan(x)')
plt.legend()
plt.show()
x = np.arange(12)
y = np.random.rand(12)
labels = ['1','2','3','4','5','6','7','8','9','10','11','12']
plt.bar(x,y,color='blue',tick_label=labels)
plt.title('bar graph')
plt.show()
size = [20,20,20,40]
plt.axis(aspect=1)
explode = [0.02,0.02,0.02,0.05]
plt.pie(size,labels=['A','B','C','D'],autopct='%.0f%%',explode=explode,shadow=True)
plt.show()
x = np.random.randn(1000)
plt.hist(x,200)
plt.show()
子图

饼图

3D图绘制
from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure()
ax = Axes3D(fig)
x = np.arange(-2,2,0.1)
y = np.arange(-2,2,0.1)
X , Y = np.meshgrid(x,y)
Z = X ** 2 + Y ** 2
ax.plot_surface(X,Y,Z,cmap=plt.get_cmap('rainbow'))
ax.set_zlim(-1,10)
plt.title('3D graph')
plt.show()
