如何将图形插入matplotlib中的新子图

时间:2013-11-24 10:00:55

标签: python matplotlib ipython-notebook

我有许多返回数字的函数,比如

def create_predef_plot():
    f, ax = plt.subplots()
    ax.plot(randn(10))
    return f, ax

如何将create_predef_plot返回的绘图插入到f2

plot1 = create_predef_plot()
f2, (ax21, ax22) = subplots(1,2)

1 个答案:

答案 0 :(得分:1)

1)这与IPython无关,它是纯matplotlib

2)常见模式是使用ax关键字参数。

def create_predef_plot( ax=None ):
    if not ax
        f, ax = plt.subplots()
    ax.plot(randn(10))
    return ax


f2, (ax21, ax22) = subplots(1,2)
create_predef_plot(ax=ax22)
相关问题