I have a function that returns a fig, ax pair. However I want to put that result inside a subplot of my 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
Any idea on how to do this?
It's non-trivial to pass an
Axesobject created on oneFigureto a different instance of aFigureobject asAxesare designed to live on one specificFigureinstance. See this SO answer.I would recommend changing your
draw_footlball_fieldfunction to accept anAxesobject.Now you can do something along the lines of: