cartopy: how to add an image on top of map

烂漫一生 提交于 2021-01-28 05:22:53

问题


How to overlay a custom image on top of a cartopy map?

If I do

ax = plt.axes(projection=map_quest_aerial.crs)
ax.set_extent([lon_0, lon_1, lat_0, lat_1])
plt.imshow('myimage.png', extent=(x0,x1,y0,y1))
plt.show()

my image shows up correctly in the axes. But, if I try to add the background map image, my image no longer appears:

ax = plt.axes(projection=map_quest_aerial.crs)
ax.set_extent([lon_0, lon_1, lat_0, lat_1])
ax.add_image(map_quest_aerial, 10)
plt.imshow('myimage.png', extent=(x0,x1,y0,y1))
plt.show()

results in just the map image.

Is this because the map image is really just a factory that generates the map image only at the draw command and thus clobbers my image?


回答1:


This sounds like a problem with the order of drawing. I think you need to set the zorder parameter in your call to imshow, try using a large number to get the image to draw on top of the background:

plt.imshow('myimage.png', extent=(x0, x1, y0, y1), zorder=10)


来源:https://stackoverflow.com/questions/22386876/cartopy-how-to-add-an-image-on-top-of-map

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