方法一(subplot)
创建画布
from matplotlib import pyplot as plt#引用库
fig=plt.figure()#创建画布
创建子图(subplot函数)
- 功能:Add a subplot to the current figure.(向当前画布添加一个子图)
- 参数
subplot(nrows, ncols, index, **kwargs)
前三位参数分别为子图的行数和列数,共创建nrows x nclos个子图index表示第几个子图(注意index从1开始)
- 例子
在画布上创建4个子图,行列均是2(第三个参数不可缺省)
ax1=plt.subplot(2,2,1)
ax2=plt.subplot(2,2,2)
ax3=plt.subplot(2,2