【问题标题】:Python subplot 3 plots in 2x2 matrix (pyramid)Python subplot 3 绘制 2x2 矩阵(金字塔)
【发布时间】:2020-03-06 14:21:38
【问题描述】:

我想绘制一个子图,如版本“a)”中所示。 如果我使用plt.subplot2gridcolspan=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)

提前致谢!

【问题讨论】:

    标签: python matplotlib subplot


    【解决方案1】:

    您可以将网格更改为 (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)
    

    输出:

    【讨论】:

      【解决方案2】:

      使用坐标区的set_aspect 函数来控制坐标区的形状。具体来说,在您给出的示例中,添加以下行:

      ax3.set_aspect('equal')
      

      得到您在 (a) 中所描绘的内容。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-09-05
        • 2021-08-20
        相关资源
        最近更新 更多