matplotlib中画图的方式
1、matplotlib中,figure是最基础的对象,是一块总的画布,可以对画布es小背景等设置(画板/背景)
2、几乎所有的画图都是在axes上完成的(灵活的子图)
3、subplot是特殊的axes(对齐坐标的子图)
fig = plt.figure()
# C1
ax1 = fig.add_subplot(221)
ax1.plot([1,2,3])
print(type(ax1))
<class ‘matplotlib.axes._subplots.AxesSubplot’>
fig = plt.figure()
# C2
ax2 = plt.subplot(221) #底层调用add_subplot
ax2.plot([1,2,3])
print(type(ax2))
<class ‘matplotlib.axes._subplots.AxesSubplot’>
# C3
fig, ax = plt.subplots(2,2) #创建了figure和axes对象
ax3 = ax[0,0]
ax3.plot([1,2,3])
print(type(ax3))
<class ‘matplotlib.axes._subplots.AxesSubplot’>
fig = plt.figure()
#C4
ax4 = fig.add_axes([0.1,0.1,0.8,0.8])
ax4.plot([1,2,3])
print(type(ax4))
#这个例子展示了axes与subplot的关系——subplot是axes的特殊
<class ‘matplotlib.axes._axes.Axes’>
参考资料
https://www.zhihu.com/question/51745620