Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

On adjusting margins in matplotlib

I am trying to minimize margins around a 1X2 figure, a figure which are two stacked subplots. I searched a lot and came up with commands like:

self.figure.subplots_adjust(left=0.01, bottom=0.01, top=0.99, right=0.99)

Which leaves a large gap on top and between the subplots. Playing with these parameters, much less understanding them was tough (things like ValueError: bottom cannot be >= top)

enter image description here


My questions :

What is the command to completely minimize the margins?

What do these numbers mean, and what coordinate system does this follow (the non-standard percent thing and origin point of this coordinate system)? What are the special rules on top of this coordinate system?

Where is the exact point this command needs to be called? From experiment, I figured out it works after you create subplots. What if you need to call it repeatedly after you resize a window and need to resize the figure to fit inside?

What are the other methods of adjusting layouts, especially for a single subplot?

like image 926
Jesvin Jose Avatar asked Jun 15 '12 10:06

Jesvin Jose


1 Answers

They're in figure coordinates: http://matplotlib.sourceforge.net/users/transforms_tutorial.html

To remove gaps between subplots, use the wspace and hspace keywords to subplots_adjust.

If you want to have things adjusted automatically, have a look at tight_layout

Gridspec: http://matplotlib.sourceforge.net/users/gridspec.html

like image 95
Joe Kington Avatar answered Sep 23 '22 19:09

Joe Kington