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:
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:
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