I need to make a plot (with errorbars) with ellipses as markers. After some searching I came up with Ellipse in matplotlib.patches. Then I could draw the error bars with plt.errorbar. But the problem is that even though I give the error bar command first, the error bars are always drawn in the foreground and the ellipses are drawn on the background, no matter what order I give in the program.
Does any one know of a better way to create an ellipse as a marker (each point will have a different eccentricity) with error bars? Or at least guide me in how to put the error bars in the background?
Here is a minimal example of what I have so far:
import matplotlib.pyplot as plt
from matplotlib.backends.backend_pdf import PdfPages
from matplotlib.patches import Ellipse
PlotFileName="test.pdf"
pdf = PdfPages(PlotFileName)
fig=plt.figure(1)
ax1=fig.add_subplot(111)
plt.xlim([1,4])
plt.ylim([2,8])
ax1.errorbar([2.5], [5], yerr=[1], fmt="o", color="black", ms=0.1)
ax1.add_artist(Ellipse((2.5, 5), 1, 1, facecolor="green", edgecolor="black"))
pdf.savefig(fig)
pdf.close()
plt.close()
and here is how it looks:

I want the error bar to go in the background of the ellipse.
Thanks in advance…
Use the zorder specifier for both your plot commands.
From the documentation: “Set the zorder for the artist. Artists with lower zorder values are drawn first.”