ich ein geografisches Heatmap mit cartopy und matplotlib gemacht haben, von der Anzahl der Benutzer meiner app, aber Probleme habe eine colorbar Legende hinzufügen:Make colorbar Legende in Matplotlib/Cartopy
import cartopy.crs as ccrs
import cartopy.io.shapereader as shpreader
import matplotlib.pyplot as plt
import matplotlib as mpl
import numpy as np
cmap = mpl.cm.Blues
# Countries is a dictionary of {"country_name": number of users}, for example
countries = {"United States": 100, "Canada": 50, "China": 10}
max_users = float(max(countries.values()))
shapename = 'admin_0_countries'
countries_shp = shpreader.natural_earth(resolution='110m', category='cultural', name=shapename)
ax = plt.axes(projection=ccrs.Robinson())
for country in shpreader.Reader(countries_shp).records():
name = country.attributes['name_long']
num_users = countries[name]
ax.add_geometries(country.geometry, ccrs.PlateCarree(),
facecolor=cmap(num_users/max_users, 1))
plt.savefig('iOS_heatmap.png', transparent=True, dpi=900)
Ich möchte eine Farbbalkenlegende hinzufügen. Es gibt eine Dokumentation für ein einfaches Matplotlib-Plot, aber ich bin mir nicht sicher, wie man es durch Cartopy macht, wo die Achse ein GeoAxesSubplot
ist. Jede Hilfe zum Hinzufügen der Legende wäre willkommen.
Ich würde auch gerne Tipps, welche Bibliothek ist am besten für diese Art von geografischen Heatmaps. Ich muss als nächstes eine Heatmap von Benutzern in den USA erstellen, und Cartopy scheint nicht die beste Option zu sein. Vielen Dank!