【问题标题】:how to insert a figure into a new subplot in matplotlib [duplicate]如何将图形插入matplotlib中的新子图中[重复]
【发布时间】:2013-11-24 10:00:55
【问题描述】:

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

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)

【问题讨论】:

标签: python matplotlib ipython-notebook


【解决方案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)

【讨论】:

    猜你喜欢
    • 2019-10-04
    • 2014-08-29
    • 2020-05-05
    • 1970-01-01
    • 2018-12-23
    • 1970-01-01
    • 2021-04-14
    • 2017-12-24
    • 2014-12-15
    相关资源
    最近更新 更多