colorbar und plot

Wenn du dir nicht sicher bist, in welchem der anderen Foren du die Frage stellen sollst, dann bist du hier im Forum für allgemeine Fragen sicher richtig.
Antworten
Samoth
User
Beiträge: 41
Registriert: Freitag 24. November 2017, 15:13

Hallo,
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)
Woran könnte das liegen? Der Fehler ensteht bei der letzten Zeile. Danke
Benutzeravatar
MagBen
User
Beiträge: 799
Registriert: Freitag 6. Juni 2014, 05:56
Wohnort: Bremen
Kontaktdaten:

Hier
https://stackoverflow.com/questions/181 ... atch-graph
werden verschiedene Lösungen diskutiert.
a fool with a tool is still a fool, www.magben.de, YouTube
Antworten