Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to combine matplotlib figures into multiple subplots?

Using matplotib I have several Figure objects being returned from different plotting functions. The figures are expensive to produce with specific formatting for each one, [fig1, fig2, fig3, fig4].

I need to arrange these in different layouts. For examples a column containing fig1, fig3, fig4; a row containing all figures; a 2x2 grid of all figures, and so on. I looked at pyplot.subplots but this returns an array of axes that cannot be set.

How do I combine these separate figure objects into multiple subplots?

My actual case has 20+ expensive figures that need to be arranged in several different layouts so I really cannot re-plot the figures for every layout combination.

like image 556
Edmund Avatar asked Nov 19 '25 10:11

Edmund


1 Answers

did you mean somethink like THIS:

import matplotlib.pyplot as plt
fig, axs = plt.subplots(ncols=3, nrows=3)
gs = axs[1, 2].get_gridspec()
# remove the underlying axes
for ax in axs[1:, -1]:
   ax.remove()
axbig = fig.add_subplot(gs[1:, -1])
axbig.annotate('Big Axes \nGridSpec[1:, -1]', (0.1, 0.5),
           xycoords='axes fraction', va='center')
fig.tight_layout()
plt.show()
like image 94
Raul Daniel Corona Avatar answered Nov 20 '25 22:11

Raul Daniel Corona



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!