Python 子图 2x2 矩阵中的 3 个图(金字塔)
Python subplot 3 plots in 2x2 matrix (pyramid)
我想绘制一个子图,如版本 "a)" 所示。
如果我使用 plt.subplot2grid
和 colspan=2
我得到版本 "b)" 我不想要的。
这是我当前的代码:
ax1.subplot2grid((2,2), (0,0))
ax1.plot(m[:,0], m[:,8], color = "0")
ax2.subplot2grid((2,2), (0,1))
ax2.plot(m[:,0], m[:,9], color = "0")
ax3.subplot2grid((2,2), (1,0))
ax3.plot(m[:,0], m[:,10], color = "0", colespan=2)
提前致谢!
使用轴的 set_aspect
函数控制轴的形状。具体来说,在您给出的示例中,添加以下行:
ax3.set_aspect('equal')
获取您在 (a) 中所描绘的内容。
您可以将网格更改为 (2,4)
并在每个轴上放置 colspan=2
:
m = np.array([[0,1],[1,0]])
fig = plt.figure()
ax = plt.subplot2grid((2,4),(0,0), colspan=2)
ax.imshow(m)
ax1 = plt.subplot2grid((2,4),(0,2), colspan=2)
ax1.imshow(m)
ax2 = plt.subplot2grid((2,4),(1,1), colspan=2)
ax2.imshow(m)
输出:
我想绘制一个子图,如版本 "a)" 所示。
如果我使用 plt.subplot2grid
和 colspan=2
我得到版本 "b)" 我不想要的。
这是我当前的代码:
ax1.subplot2grid((2,2), (0,0))
ax1.plot(m[:,0], m[:,8], color = "0")
ax2.subplot2grid((2,2), (0,1))
ax2.plot(m[:,0], m[:,9], color = "0")
ax3.subplot2grid((2,2), (1,0))
ax3.plot(m[:,0], m[:,10], color = "0", colespan=2)
提前致谢!
使用轴的 set_aspect
函数控制轴的形状。具体来说,在您给出的示例中,添加以下行:
ax3.set_aspect('equal')
获取您在 (a) 中所描绘的内容。
您可以将网格更改为 (2,4)
并在每个轴上放置 colspan=2
:
m = np.array([[0,1],[1,0]])
fig = plt.figure()
ax = plt.subplot2grid((2,4),(0,0), colspan=2)
ax.imshow(m)
ax1 = plt.subplot2grid((2,4),(0,2), colspan=2)
ax1.imshow(m)
ax2 = plt.subplot2grid((2,4),(1,1), colspan=2)
ax2.imshow(m)
输出: