here's a quick thing which is quite annoying me. I've followed the indications found in strange matplotlib zorder behavior with legend and errorbar but it doesn't work. Here's a very brief working example
x = np.linspace(0,10)
y = (x-5)**2
plt.plot(x,y,label='test curve',zorder=100)
plt.legend(loc='center right').set_zorder(102)
If you try this you will see that the legend is still underneath the curve, despite the zordering. Does anyone know why?

I'm using matplotlib 1.3.1 on ipython 3.1.0
Following on from @cel's comment, I agree you need to add an opaque background to the legend. Try adding:
leg=plt.legend(loc='center right')
leg.set_zorder(102)
leg.get_frame().set_facecolor('w')
Its also possible to set legend.facecolor in your matplotlibrc or via plt.rcParams
Alternatively make sure the fill of the legend frame is set to True:
print leg.get_frame().get_fill()
If that prints False, try
leg.get_frame().set_fill(True)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With