Combine several Matplotlib figures into one

Viewed 1092

Assume a library function that creates a figure internally:

def plot_data(data):  # cannot change this implementation
   ...
   fig, ax = plt.subplots(1, figsize=(w, h))
   ax.plot(...)
   ...
   return fig, ax

I create two plots using the above function:

fig1, ax1 = plot_data(data1)
fig2, ax2 = plot_data(data2)

How can I put these two plots/figures side by side? A naive approach is as follows (does not work this way):

fig0, ax0 = plt.subplots(1, 2, figsize=(w, h))
ax0[0] = ax1
ax0[1] = ax2
plt.close(fig1)
plt.close(fig2)
plt.show()
0 Answers
Related