I would like to use the axes handle returned by an external function to place the plot objects from that axes within my chosen subplot located in another figure. The format of the external function can't be modified. The below code is a dummy example that represents the structure of the code I am working with.
I am hoping there's an inbuilt function to do this such as set_figure() but I could not find one. Any help is appreciated.
import matplotlib.pyplot as plt
def myfunc():
plt.figure()
plt.text(0.5,0.5,s='plot from\nexternal function')
return plt.gca()
plt.subplot(311)
plt.text(0.5,0.5,s='subplot 1')
plt.subplot(312)
plt.text(0.5,0.5,s='subplot 2')
plt.subplot(313)
ax = myfunc()
# how can I make the plot generated by myfunc appear in the third subplot
# and close the figure from the external function so it does not show?
plt.show()
The desired output looks like this: