注意
转到末尾下载完整的示例代码。
多个子图#
包含多个子图的简单演示。
更多选项请参阅使用 plt.subplots 创建多个子图。
subplots()
是生成简单子图排列的推荐方法。
fig, (ax1, ax2) = plt.subplots(2, 1)
fig.suptitle('A tale of 2 subplots')
ax1.plot(x1, y1, 'o-')
ax1.set_ylabel('Damped oscillation')
ax2.plot(x2, y2, '.-')
ax2.set_xlabel('time (s)')
ax2.set_ylabel('Undamped')
plt.show()

子图也可以使用subplot()
逐个生成。
plt.subplot(2, 1, 1)
plt.plot(x1, y1, 'o-')
plt.title('A tale of 2 subplots')
plt.ylabel('Damped oscillation')
plt.subplot(2, 1, 2)
plt.plot(x2, y2, '.-')
plt.xlabel('time (s)')
plt.ylabel('Undamped')
plt.show()

脚本总运行时间:(0 分钟 1.943 秒)