ich versuche gerade eine Colorbar an die Größe meines plots anzugleichen.
Allerdings bekomme ich immer der vielsagenden Fehler: KeyError: 'map_projection'
Code: Alles auswählen
if __name__ == '__main__':
#plane projection of the world
#map with box size (defintion on the top)
box = sgeom.box(minx=llcrnrlon, maxx=urcrnrlon, miny=llcrnrlat, maxy=urcrnrlat)
x0, y0, x1, y1 = box.bounds
#Map plot. The middel of the map is central_longitude
proj = ccrs.PlateCarree(central_longitude=0)
#Verschiebung, Mittelpunkt Box
box_proj = ccrs.PlateCarree(central_longitude=0)
ax2 = plt.axes(projection=proj)
ax2.set_extent([x0, x1, y0, y1], box_proj)
ax2.add_feature(cartopy.feature.BORDERS, linestyle='-', alpha=.5)
ax2.coastlines(resolution='50m')
gl = ax2.gridlines(ccrs.PlateCarree(), \
linestyle='--', alpha=1, linewidth=0.5, draw_labels=True)
gl.xlocator = mticker.FixedLocator([-30, -20, -10, 0, 10, 20, 30])
gl.ylocator = mticker.FixedLocator([-30, -20, -10, 0, 10, 20, 30, 40])
gl.xlabels_top = False
gl.ylabels_right = False
gl.xformatter = LONGITUDE_FORMATTER
gl.yformatter = LATITUDE_FORMATTER
scale_bar(ax2, ccrs.Mercator(), 1000) # 100 km scale bar
# or to use m instead of km
# scale_bar(ax, ccrs.Mercator(), 100000, m_per_unit=1, units='m')
# or to use miles instead of km
# scale_bar(ax, ccrs.Mercator(), 60, m_per_unit=1609.34, units='miles')
#Add colorbar with same plotsize
divider = make_axes_locatable(ax2)
cax = divider.append_axes("right", size="5%", pad=0.05)