errorbar plot caps

Hi mpl users,

I have noticed that when making a figure using the errorbar function, a cap line will show up over a marker if they happen to fall on top of one another. The line connecting the caps is (properly) hidden under the marker. This behavior only occurs if the overlapping marker was placed on the plot before the overlapping errorbar.

The following code demonstrates the problem:

errorbar([1,2,3],[3,3,3],color='black',mfc='white',marker='s',ms=14)
errorbar([1,2,3],[2,2,2],[1,1,1],color='black')
ylim(0,4)

···

--
Chris

That's a good one!

Here's what I see happening: By default (without manually specifying zorder), all Collections are drawn before all Lines. In an errorbar, the data itself and the caps are both drawn using Lines, but the errorbar is drawn using a LineCollection. So what you're seeing is a strange interleaving of different parts of the errorbar plot.

By forcing zorder on these things, you can get the artists associated with each errorbar call to render together in the overall ordering -->

errorbar([1,2,3],[3,3,3],color='black',mfc='white',marker='s',ms=14,zorder=10)
errorbar([1,2,3],[2,2,2],[1,1,1],color='black',zorder=20)

Unfortunately, it's a messy, non-obvious workaround.

IMHO, the way the default zorder works is probably due for an overhaul, but it's a pretty core thing to be messing with and risks breaking a lot of existing plots. For example, I've never quite understood why all collections are drawn before all lines (and exist in separate artist lists), rather than just interleaving them as they are added to the plot. But I wasn't around to see that develop, so I may just misunderstand. And I don't really have the time to do this now, so I should probably keep quiet :wink:

Cheers,
Mike

Christopher Brown wrote:

···

Hi mpl users,

I have noticed that when making a figure using the errorbar function, a cap line will show up over a marker if they happen to fall on top of one another. The line connecting the caps is (properly) hidden under the marker. This behavior only occurs if the overlapping marker was placed on the plot before the overlapping errorbar.

The following code demonstrates the problem:

errorbar([1,2,3],[3,3,3],color='black',mfc='white',marker='s',ms=14)
errorbar([1,2,3],[2,2,2],[1,1,1],color='black')
ylim(0,4)

--
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA