Skip to content

Commit d6881f0

Browse files
committed
MNT: use zorder for barsabove
1 parent 06e55e6 commit d6881f0

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2793,6 +2793,7 @@ def errorbar(self, x, y, yerr=None, xerr=None,
27932793
.. plot:: mpl_examples/statistics/errorbar_demo.py
27942794
27952795
"""
2796+
kwargs.setdefault('zorder', 2)
27962797

27972798
if errorevery < 1:
27982799
raise ValueError(
@@ -2850,17 +2851,13 @@ def errorbar(self, x, y, yerr=None, xerr=None,
28502851

28512852
l0 = None
28522853

2853-
# Instead of using zorder, the line plot is being added
2854-
# either here, or after all the errorbar plot elements.
2855-
if barsabove and plot_line:
2856-
# in python3.5+ this can be simplified
2857-
eb_style = dict(base_style)
2858-
eb_style.update(**kwargs)
2859-
l0 = mlines.Line2D(x, y, **eb_style)
2860-
self.add_line(l0)
28612854
# make the style dict for the 'normal' plot line
28622855
plot_line_style = dict(base_style)
28632856
plot_line_style.update(**kwargs)
2857+
if barsabove:
2858+
plot_line_style['zorder'] = kwargs['zorder'] - .1
2859+
else:
2860+
plot_line_style['zorder'] = kwargs['zorder'] + .1
28642861

28652862
# make the style dict for the line collections (the bars)
28662863
eb_lines_style = dict(base_style)
@@ -2903,6 +2900,10 @@ def errorbar(self, x, y, yerr=None, xerr=None,
29032900
eb_cap_style[key] = kwargs[key]
29042901
eb_cap_style['color'] = ecolor
29052902

2903+
if plot_line:
2904+
l0 = mlines.Line2D(x, y, **plot_line_style)
2905+
self.add_line(l0)
2906+
29062907
barcols = []
29072908
caplines = []
29082909

@@ -3067,12 +3068,6 @@ def extract_err(err, data):
30673068
for l in caplines:
30683069
self.add_line(l)
30693070

3070-
if not barsabove and plot_line:
3071-
# in python3.5+ this can be simplified
3072-
eb_style = dict(base_style)
3073-
eb_style.update(**kwargs)
3074-
l0 = mlines.Line2D(x, y, **eb_style)
3075-
self.add_line(l0)
30763071

30773072
self.autoscale_view()
30783073
self._hold = holdstate

0 commit comments

Comments
 (0)