I'm trying to add a color bar to my plot, which contains 4 subplots. I've added the subplots manually using this code:
extent = [-8, 37, 28, 46]
fig = plt.figure(figsize=(5.5, 3.5), constrained_layout= False)
spec = fig.add_gridspec(ncols=2, nrows=2)
ax0 = fig.add_subplot(spec[0, 0], projection=ccrs.PlateCarree(), frameon= False)
ax0.set_extent(extent)
ax1 = fig.add_subplot(spec[0, 0], projection=ccrs.PlateCarree(), frameon= False)
ax1.set_extent(extent)
I wrote these lines up to ax3.
Now that I try to make a color bar, using plt.color bar()
It adds a color bar only to the last subplot... I've tried other online solutions, but they all use the fig, axes= plt.subplots(...)
which I don't use..
edit- this question How to have one colorbar for all subplots doesn't really help me... when I try to run this code
fig.subplots_adjust(right=0.8)
cbar_ax = fig.add_axes([0.85, 0.15, 0.05, 0.7])
fig.colorbar(ax3, cax=cbar_ax)
I get this error- AttributeError: 'GeoAxesSubplot' object has no attribute 'get_array' I'm using Cartopy to make a hist2d of global occurrences.
Does anyone have an idea how to overcome this? Thanks in advance, Karin.