5

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?

1
  • if you have a fixed aspect ratio (imshow?), maybe a look at this question can help you Commented Jun 15, 2012 at 21:24

1 Answer 1

9

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

Sign up to request clarification or add additional context in comments.

2 Comments

I included a pic of my problem (large gap on top and between the subplots.). Could you resolve that?
It looks like you're using a subplot (the top one) with a fixed aspect ratio? In that case, the adjustable part of the plot is the "box" of the subplot (rather than the data limits). The subplot spacing will be applied and then the subplot's outline will be adjusted so that the aspect ratio is correct. If you want axes to take up different porportions of the figure, don't use a subplot that tells them to take up the same porportion of the figure. Look into gridspec, or just manually adding the axes, in that case.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.