【问题标题】:How to arrange nested subplots in Matplotlib? [duplicate]如何在 Matplotlib 中安排嵌套的子图? [复制]
【发布时间】:2019-11-01 18:11:06
【问题描述】:

我有 3 个垂直排列的地块,代码如下:

plt.figure(1)
plt.subplot(311)
plt.plot(z2, 'blue')
plt.plot(mid2, 'orange')
plt.plot(z3, 'red')
plt.plot(mid3, 'orange')
plt.subplot(312)
plt.plot(z)
plt.plot(mid)
plt.subplot(313)
plt.plot(proportional, "black")

但我想做的是在第一个情节(311)旁边添加另一个情节。我的意思是我想在第一行内有两个图,然后像以前一样在接下来的两行内显示一个图(我喜欢在一个图中显示 z2,mid2 而在旁边的另一个图中显示 z3,mid3 ,都在第一行内) .如果可以,我该怎么做?

【问题讨论】:

    标签: python matplotlib subplot


    【解决方案1】:

    我再举一个例子。此代码plt.subplot(324) 将使您的图形成为一个 3x2 表格(3 行和 2 列)并在“单元格 4”上创建一个坐标。见下图 所以,如果你想在“单元格 1”上绘制 z2mid2,那么 plt.subplot(321)plot 它们。

    您可能想在“单元格 3”和“单元格 4”上绘制 zmid,然后

    plt.subplot(312)
    

    (一个3x1的表格,在“单元格2”上做一个坐标,相当于一个3x2的表格,在“单元格3”和“单元格4”上都有一个坐标)

    所以你的代码可能是这样的:

    plt.figure(1)
    
    plt.subplot(321)             # "cell 1"
    plt.plot(z2, 'blue')
    plt.plot(mid2, 'orange')
    
    plt.subplot(322)             # "cell 2"
    plt.plot(z3, 'red')
    plt.plot(mid3, 'orange')
    
    plt.subplot(312)             # "cell 3" and "cell 4"
    plt.plot(z)
    plt.plot(mid)
    
    plt.subplot(313)             # "cell 5" and "cell 6"
    plt.plot(proportional, "black")
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-02
    • 1970-01-01
    • 2013-09-24
    • 2013-08-12
    • 2013-07-01
    相关资源
    最近更新 更多