https://jakevdp.github.io/PythonDataScienceHandbook/04.08-multiple-subplots.html
plt.subplots()
## axes are in a two-dimensional array, indexed by [row, col]
fig, ax = plt.subplots(2, 3, sharex='col', sharey='row')
for i in range(2):
for j in range(3):
ax[i, j].text(0.5, 0.5, str((i, j)),
fontsize=18, ha='center')
In comparison to plt.subplot(), plt.subplots() is more consistent with Python's conventional 0-based indexing.

plt.subplot()
for i in range(1, 7):
plt.subplot(2, 3, i)
plt.text(0.5, 0.5, str((2, 3, i)),
fontsize=18, ha='center')

本文介绍了如何使用matplotlib库中的plt.subplots函数来创建二维子图网格。与plt.subplot相比,plt.subplots更符合Python的0基索引惯例,使得子图的管理和布局更为直观。文章通过实例展示了如何设置共享x轴和y轴的子图,以及如何在每个子图中显示位置信息。

被折叠的 条评论
为什么被折叠?



