4

I am trying to add an image "stamp" on top of a weather plot, but the image is below other data.

Is there a way to force the image to be on top of other plot data (like filled contintents, and contourf plots).

This nearly works, but it does not put the image on top:

Python Matplotlib Basemap overlay small image on map plot

Here is a sample code that shows the problem:

import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap
import numpy as np

lats = np.arange(45., 60., 0.5)
lons = np.arange(-15., 5., 0.5)

m = Basemap(projection='cyl', llcrnrlon=min(lons)-2, llcrnrlat=min(lats)-2,
            urcrnrlon=max(lons)+2, urcrnrlat=max(lats)+2, resolution='l')

x, y = m(lons,lats)

m.drawcoastlines()
m.fillcontinents()

x0 = np.min(x)
y0 = np.min(y)+3
x1 = x0+(np.max(x)-np.min(x))/2.
y1 = y0+(np.max(y)-np.min(y))/2.
im = plt.imshow(plt.imread('MCC-logo.gif'), extent=(x0, x1, y0, y1), alpha=0.9)

plt.show()

( I can't post an image yet - I've just joined stackoverflow)

I want the blue stamp to be on top, but can't figure out what to do...

Community
  • 1
  • 1
  • Aha! Forget it - I was using the second answer in the above link. The first answer actually works. I should have used OffsetImage and AnnotationBbox. This successfully places the image on top of the plot data. – Conor Sweeney Jul 13 '15 at 16:53

2 Answers2

0

Aha! Forget it - I was using the second answer in the above link. The first answer actually works. I should have used OffsetImage and AnnotationBbox. This successfully places the image on top of the plot data.

0

More generally, you can use the zorder parameter to control which artists are drawn on top.

user670416
  • 736
  • 4
  • 12