3

I often make series of subplots with mpl_toolkits.basemap.Basemap projections, which generates geographic projections on axes with fixed aspect ratios. When I use fig.tight_layout(), this adjusts only the axes to be tight inside the bounding figure window -- so if the axes aren't allowed to have changed aspect ratios, this will often leave huge amounts of whitespace -- note this cannot be fixed by using bbox_inches='tight' in figsave(), because e.g. 2x2 networks of fixed-AR subplots will have extra interior whitespace.

Here's an example, where each axis has aspect 1: enter image description here

Is there a way I can adjust the figure to be tight around the inner axes objects? Note this method would necessarily eliminate extra interior whitespace -- fixed-aspect ratio axes are centered in their GridSpec zone (e.g. the lower-right quadrant) until the total figure height/width is such that the aspect ratio of their GridSpec zone matches the axes aspect ratio.

Ideally, this method should work for the "outer bounding box" of each axes including its labels, titles, etc, rather than the box itself. One way would be to retrieve the aspect ratios of each subplot and adjust figsize accordingly, but that leaves the problem of room for titles, ticklabels, etc.; we really want the outer-bounding box aspect ratios.

Luke Davis
  • 2,548
  • 2
  • 21
  • 43
  • Can you add a [mcve]? – Andrey Sobolev Mar 01 '17 at 08:07
  • @AndreySobolev Yup, just did. – Luke Davis Mar 01 '17 at 08:15
  • I guess you need to adjust figure aspect ratio manually to get rid of the whitespace. If there are any other options, I'd be happy to know them too – Andrey Sobolev Mar 01 '17 at 08:27
  • I think it's hard to get something like the "outer bounding box' aspect". Did you have a look at [this question](http://stackoverflow.com/questions/42475508/how-to-combine-gridspec-with-plt-subplots-to-eliminate-space-between-rows-of-s)? You would have to set the spacings manually, but a space of `0.3` is usually not too bad, I would guess. – ImportanceOfBeingErnest Mar 01 '17 at 08:30
  • @ImportanceOfBeingErnest Neat; is there a way to retrieve the auto-generated `hspace` and `wspace` between each subplot, or does it have to be explicitly declared when the subplot structure is drawn? – Luke Davis Mar 01 '17 at 08:38
  • Isn't the main point here that the automatic settings do not apply for fixed aspect subplots? What would you gain from retrieving them? – ImportanceOfBeingErnest Mar 01 '17 at 08:42
  • Oh nevermind; I was thinking there could be some retrievable `hspace` and `wspace` refering to the "limiting" space between subplots -- the minimum space that would be left when the figure is reshaped such that "extra" whitespace disappears. At least, I think this would be the case if `hspace` and `wspace` were manually specified for a network of fixed-AR subplots. – Luke Davis Mar 01 '17 at 08:47

0 Answers0