Make colorbar legend in Matplotlib/Cartopy

狂风中的少年 提交于 2019-12-05 08:22:14

I think that add_geometries() returns a FeatureArtist rather than some Matplotlib mappable object that can be passed to colorbar(). The simplest solution I can think of is to create your own mappable and use that to create the colorbar. Try placing these lines after your country loop:

sm = plt.cm.ScalarMappable(cmap=cmap,norm=plt.Normalize(0,1))
sm._A = []
plt.colorbar(sm,ax=ax)

Incidently, this kind of geographical heatmap is called a choropleth map.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!