Reputation: 167
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?
Upvotes: 1
Views: 3716
Reputation: 3333
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)
Upvotes: 2