Python 将轴复制到matplotlib中的gridspec中

Python 将轴复制到matplotlib中的gridspec中,python,matplotlib,Python,Matplotlib,我有一个返回fig,ax对的函数。但是,我想将该结果放在我的gridspec的子批中 fig, ax = draw_football_field(dimensions, size) # this is the output that I want to copy to another subplot fig = plt.figure(constrained_layout=True) gs = fig.add_gridspec(18, 9) ax = fig.add_subplot(gs[3:6

我有一个返回
fig,ax
对的函数。但是,我想将该结果放在我的
gridspec
的子批中

fig, ax = draw_football_field(dimensions, size) # this is the output that I want to copy to another subplot

fig = plt.figure(constrained_layout=True)
gs = fig.add_gridspec(18, 9)
ax = fig.add_subplot(gs[3:6, 1:3], zorder=1) #this is the target subplot

你知道怎么做吗?

将在一个
图形
上创建的
对象传递到一个
图形
对象的不同实例是非常重要的,因为
被设计为生活在一个特定的
图形
实例上

我建议更改
draw\u footlball\u字段
函数以接受
对象

def draw_football_field(axes, other_args):
    axes.plot(other_args)
    return axes
现在,您可以按照以下步骤进行操作:

fig = plt.figure(constrained_layout=True)
gs = fig.add_gridspec(18, 9)
ax = fig.add_subplot(gs[3:6, 1:3], zorder=1) #this is the target subplot
ax = draw_football_field(ax, other_args) # modify axes instance from 'this' fig