1

I'm making a figure with several subplots using GridSpec. Some of the subplots are maps, so I'm using Cartopy to plot them. When calling GridSpec, the parameter wspace works, but hspace still leaves a big gap between the subplots, even when setting hspace=0. This only happens if the subplots are with cartopy.

For example, using this code:

import matplotlib.pyplot as plt
from matplotlib.gridspec import GridSpec
import cartopy.crs as ccrs
crs = ccrs.PlateCarree(central_longitude=180)

fig = plt.figure()
gs = GridSpec(2,2,wspace=0.05,hspace=0)
for k in range(0,4):
    ax = plt.subplot(gs[k],projection=crs)
    ax.set_xticks([])
    ax.set_yticks([])
    ax.coastlines()

produces:

hspace is 0

Larger values of hspace are not ignored (for instance, hspace=5 works). I found this question where on a similar problem they suggest to use ax.set_aspect('auto') or ax.set_adjustable('datalim'). In my case, both of them make hspace work for the small values. However, it deforms the shape of the original map:

deformed map

Any idea on how I could solve this, without deforming the map?

Using Python 3.7.6, Matplotlib 3.1.3, Cartopy 0.17.0

lanadaquenada
  • 395
  • 3
  • 4
  • 26
  • 3
    The aspect ratio of the subplots is fixed, and the size of the figure is fixed, so there will be blank space somewhere. If you don't want so much blank space, make the figure smaller in the y-direction by adjusting height: `plt.figure(figsize=(width, height)` – Jody Klymak Mar 03 '20 at 22:06
  • @JodyKlymak This works, thanks! If you are willing to answer the question I'll mark it as solved. – lanadaquenada Mar 05 '20 at 13:37

0 Answers0