2

I have 5 maps I am trying to plot in one figure. I would like them to be laid out like

1 2 3
 4 5

To do this, I tried to follow the answer given here: Position 5 subplots in Matplotlib

This gives me the correct layout, but there is a ton of empty space left between the subplots.

#S,W,N,E Bounds
lonMin = 119
lonMax = 124
latMin = 12
latMax = 19

m = Basemap(llcrnrlon=lonMin,llcrnrlat=latMin,urcrnrlon=lonMax,urcrnrlat=latMax, projection = 'cea', resolution = 'i')

fig = plt.figure()
axes = [plt.subplot2grid(shape=(2,6), loc=(0,0), colspan=2),
        plt.subplot2grid((2,6), (0,2), colspan=2),
        plt.subplot2grid((2,6), (0,4), colspan=2),
        plt.subplot2grid((2,6), (1,1), colspan=2),
        plt.subplot2grid((2,6), (1,3), colspan=2)]
for i in range(5):
    m.ax = axes[i]
    m.drawcoastlines()
fig.suptitle('Title', fontsize = 20, fontweight = 'bold')

enter image description here

How can I reduce the spacing between the subplots?

EDIT: The problem appears to somehow be tied to putting Basemaps in the plot. If I comment out the m.drawcoastlines() call, the axes look like this, which is fine: enter image description here

Community
  • 1
  • 1
hm8
  • 1,381
  • 3
  • 21
  • 41

1 Answers1

2

First of all you may try to call plt.tight_layout() to adjust spacing between subplots to minimize the overlaps.

Another way is to use subplots_adjust to set all spaces manually like

fig.subplots_adjust(hspace=.1) # height spaces
fig.subplots_adjust(wspace=.1) # width spaces

These functions affect all subplots. If you need more control use GridSpec.

Serenity
  • 35,289
  • 20
  • 120
  • 115
  • Neither of these did the trick. plt.tight_layout() got rid of the surrounding blank space but not the space between the plots (and it also made the figures overlap with the title). And fig.subplots_adjust() didn't change anything at all. – hm8 Apr 19 '17 at 16:30
  • 2
    Nevermind....I got `subplots_adjust()` to work, but only by setting the hspace/wspace values to a small negative number, for some reason... – hm8 Apr 19 '17 at 16:43