问题
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