相关疑难解决方法(0)

在matplotlib中使用多个列动态添加子图

如果我使用多个列来显示我的子图,我如何动态地将新图添加到一堆子图?回答了一个列的问题,但我似乎无法修改那里的答案,使其动态添加到带有x列的子图

我修改了Sadarthrion的答案并尝试了以下内容.在这里,为了举个例子,我做了number_of_subplots=11num_cols = 3.

import matplotlib.pyplot as plt

def plotSubplots(number_of_subplots,num_cols):
    # Start with one
    fig = plt.figure()
    ax = fig.add_subplot(111)
    ax.plot([1,2,3])

    for j in range(number_of_subplots):
        if j > 0: 
            # Now later you get a new subplot; change the geometry of the existing
            n = len(fig.axes)
            for i in range(n):
                fig.axes[i].change_geometry(n+1, num_cols, i+1)

            # Add the new
            ax = fig.add_subplot(n+1, 1, n+1)
            ax.plot([4,5,6])

            plt.show() 

   plotSubplots(11,3) 
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

正如你所看到的,这并没有给我我想要的东西.第一个图占据了所有列,其他图比它们应该小

编辑:

('2.7.6 | 64-bit …

python matplotlib

6
推荐指数
1
解决办法
8390
查看次数

标签 统计

matplotlib ×1

python ×1