Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to combine several matplotlib figures into one figure?

I have several matplotlib Figure-objects that I want to combine to one large figure by placing them next to another.

  1. How to get them into one figure?
  2. How to make them the same height?

Note that I cannot change the way the individual figures are created. I can just use the resulting Figure objects.

like image 948
Se Norm Avatar asked Mar 20 '14 01:03

Se Norm


1 Answers

It seems there is no (reliable - see bottom) matplotlib way of doing this, so one is stuck with using image processing tools on the figure-output. I'm using PNGs and PIL for that. Another possibility is using SVGs like here: http://neuroscience.telenczuk.pl/?p=331

That is a related question: matplotlib: can I create AxesSubplot objects, then add them to a Figure instance?

Here is a way that seemed to work in 2012, proposed by Joe Kington:

Axes deliberately aren't supposed to be shared between different figures now. As a workaround, you could do this fig2._axstack.add(fig2._make_key(a), a), but it's hackish and likely to change in the future. It seems to work properly, but it may break some things.

I haven't tried if it still works.

like image 153
Se Norm Avatar answered Oct 05 '22 23:10

Se Norm