【发布时间】:2018-07-22 11:40:49
【问题描述】:
在 python 中创建 (3,3) 子图矩阵的最佳方法是什么:
- 第一列包含 3 个子图
- 第二列包含 3 个子图
- 第三列包含 2 个子图
最后两个子图的大小应该相等。这意味着他们将在其他两列的中间图的中间相遇。
我尝试使用 gridspec 执行此操作,但到目前为止还没有成功。
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import gridspec
# generate some data
x = np.arange(0, 10, 0.2)
y = np.sin(x)
# plot it
fig = plt.figure(figsize=(8, 6))
gs = gridspec.GridSpec(3, 3)
ax0 = plt.subplot(gs[0])
ax0.plot(x, y)
ax1 = plt.subplot(gs[1])
ax1.plot(y, x)
ax3 = plt.subplot(gs[3])
ax3.plot(y, x)
ax4 = plt.subplot(gs[4])
ax4.plot(y, x)
ax6 = plt.subplot(gs[6])
ax6.plot(y, x)
ax7 = plt.subplot(gs[7])
ax7.plot(y, x)
plt.tight_layout()
plt.savefig('grid_figure.png')
plt.show()
【问题讨论】:
标签: python matplotlib subplot