如何在作品图中添加传奇?
我目前正在使用一些涉及土地使用类型(即森林,沙漠,水等)的数据,这些数据在我的车展图上以不同的颜色出现。我想添加一个传奇或同等学历,以显示每种颜色代表哪种土地类型,但似乎无法使其起作用。在操作映射的顶部,土地使用类型的数据绘图需要我使用PCOLORMESH。是否有任何方法可以将各种传说显示在表明每种土地使用类型的哪种颜色的彩色图中?
以下是我代码的作品部分:
proj = ccrs.LambertConformal(central_longitude=cLon, central_latitude=cLat)
res = '10m'
fig_1 = plt.figure(figsize=(20,20))
ax_1 = plt.subplot(1,1,1,projection=proj)
ax_1.set_extent([lonW,lonE,latS,latN])
ax_1.add_feature(cfeature.LAND.with_scale(res))
ax_1.add_feature(cfeature.OCEAN.with_scale(res))
ax_1.add_feature(cfeature.COASTLINE.with_scale(res))
ax_1.add_feature(cfeature.LAKES.with_scale(res), alpha = 0.5)
ax_1.add_feature(cfeature.STATES.with_scale(res));
ax_1.set_title('Land Use Type: Western United States', fontsize=20)
ax_1.pcolormesh(cat_land_lons, cat_land_lats, cat_land, transform=ccrs.PlateCarree(), zorder=3)
ax_1.legend(['Forested', 'Water', 'Desert', 'Farmland', 'Urban'])
I'm currently working with some data that involves the land use type (i.e., forested, desert, water, etc.) that comes up as different colors on my cartopy maps. I want to add a legend or equivalent that shows which land type each color represents, but can't seem to get it to work. The land use type data plotting on top of the cartopy map requires me using pcolormesh. Is there any way to get a legend of sorts onto the cartopy plot that shows which color each land use type is?
Below is my cartopy portion of my code:
proj = ccrs.LambertConformal(central_longitude=cLon, central_latitude=cLat)
res = '10m'
fig_1 = plt.figure(figsize=(20,20))
ax_1 = plt.subplot(1,1,1,projection=proj)
ax_1.set_extent([lonW,lonE,latS,latN])
ax_1.add_feature(cfeature.LAND.with_scale(res))
ax_1.add_feature(cfeature.OCEAN.with_scale(res))
ax_1.add_feature(cfeature.COASTLINE.with_scale(res))
ax_1.add_feature(cfeature.LAKES.with_scale(res), alpha = 0.5)
ax_1.add_feature(cfeature.STATES.with_scale(res));
ax_1.set_title('Land Use Type: Western United States', fontsize=20)
ax_1.pcolormesh(cat_land_lons, cat_land_lats, cat_land, transform=ccrs.PlateCarree(), zorder=3)
ax_1.legend(['Forested', 'Water', 'Desert', 'Farmland', 'Urban'])
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在不知道您的数据的情况下,很难具体。但是给出了一些示例陆生数据和分配的颜色。如果您的LCC数据不是这样的,情况可能会有所不同。
您可以定义一个colormap和归一化器:
使用对于传说:
或不使用上面摘要中的最后两行,而是将
pcoLormesh
的结果与colorbar:从Dataviz的角度来看,使用代理艺术家使用适当的传奇可能会更好,因为配色栏可能会向这些类建议某种顺序。
It difficult to be specific without knowing what your data looks like. But given some example Landcover data and assigned colors. Things might be a little different if your LCC data is not consecutive like this.
You can define a colormap and normalizer:
Using proxy artists for the legend:
Or instead of using the last two lines from the snippet above, use the result from
pcolormesh
with a colorbar:Using a proper legend with the proxy artists is probably better from a dataviz perspective, since a colorbar might suggest some sort of order to the classes.