matplotlib制图——⼦图-subplot及多图figure
import matplotlib.pyplot as pltimport numpy as npimport pandas as pdx=np.arange(1,100)fig=plt.figure()
ax1=fig.add_subplot(221) #2*2的图形 在第⼀个位置ax1.plot(x,x)
ax2=fig.add_subplot(222)ax2.plot(x,-x)
ax3=fig.add_subplot(223)ax3.plot(x,x**2)
ax3=fig.add_subplot(224)ax3.plot(x,np.log(x))plt.show()
同时绘制两张图
import matplotlib.pyplot as pltimport numpy as npimport pandas as pdfig1=plt.figure()
ax1=fig1.add_subplot(111)ax1.plot([1,2,3],[3,2,1])fig2=plt.figure()
ax2=fig2.add_subplot(111)ax2.plot([1,2,3],[1,2,3])plt.show()