Skip to content

Commit 3e53330

Browse files
committed
WIP: start to use artists directly in errorbar
Instead of using calls to `plt.plot`
1 parent 6da2d60 commit 3e53330

File tree

1 file changed

+46
-30
lines changed

1 file changed

+46
-30
lines changed

lib/matplotlib/axes/_axes.py

+46-30
Original file line numberDiff line numberDiff line change
@@ -2785,9 +2785,9 @@ def errorbar(self, x, y, yerr=None, xerr=None,
27852785

27862786
if fmt is None:
27872787
fmt = 'none'
2788-
msg = ('Use of None object as fmt keyword argument to '
2789-
+ 'suppress plotting of data values is deprecated '
2790-
+ 'since 1.4; use the string "none" instead.')
2788+
msg = ('Use of None object as fmt keyword argument to ' +
2789+
'suppress plotting of data values is deprecated ' +
2790+
'since 1.4; use the string "none" instead.')
27912791
warnings.warn(msg, mplDeprecation, stacklevel=1)
27922792

27932793
plot_line = (fmt.lower() != 'none')
@@ -2800,11 +2800,12 @@ def errorbar(self, x, y, yerr=None, xerr=None,
28002800
if ('color' in kwargs or 'color' in fmt_style_kwargs or
28012801
ecolor is not None):
28022802
base_style = {}
2803+
if 'color' in kwargs:
2804+
base_style['color'] = kwargs.pop('color')
28032805
else:
28042806
base_style = six.next(self._get_lines.prop_cycler)
28052807

28062808
base_style['label'] = '_nolegend_'
2807-
base_style['color'] = kwargs.pop('color')
28082809
base_style.update(fmt_style_kwargs)
28092810
if ecolor is not None:
28102811
base_style['color'] = ecolor
@@ -2835,12 +2836,15 @@ def errorbar(self, x, y, yerr=None, xerr=None,
28352836
# in python3.5+ this can be simplified
28362837
eb_style = dict(base_style)
28372838
eb_style.update(**kwargs)
2838-
l0, = self.plot(x, y, **eb_style)
2839+
l0 = mlines.Line2D(x, y, **eb_style)
2840+
self.add_line(l0)
28392841

28402842
barcols = []
28412843
caplines = []
28422844

28432845
lines_kw = dict(base_style)
2846+
lines_kw.pop('marker', None)
2847+
lines_kw.pop('linestyle', None)
28442848
if elinewidth:
28452849
lines_kw['linewidth'] = elinewidth
28462850
else:
@@ -2854,9 +2858,9 @@ def errorbar(self, x, y, yerr=None, xerr=None,
28542858
# arrays fine here, they are booleans and hence not units
28552859
def _bool_asarray_helper(d, expected):
28562860
if not iterable(d):
2857-
lolims = np.asarray([d] * expected, bool)
2861+
return np.asarray([d] * expected, bool)
28582862
else:
2859-
lolims = np.asarray(lolims, bool)
2863+
return np.asarray(lolims, bool)
28602864

28612865
lolims = _bool_asarray_helper(lolims, len(x))
28622866
uplims = _bool_asarray_helper(uplims, len(x))
@@ -2929,8 +2933,10 @@ def xywhere(xs, ys, mask):
29292933
lo, ro = xywhere(left, right, noxlims & everymask)
29302934
barcols.append(self.hlines(yo, lo, ro, **lines_kw))
29312935
if capsize > 0:
2932-
caplines.extend(self.plot(lo, yo, '|', **plot_kw))
2933-
caplines.extend(self.plot(ro, yo, '|', **plot_kw))
2936+
caplines.append(mlines.Line2D(lo, yo, marker='|',
2937+
**plot_kw))
2938+
caplines.append(mlines.Line2D(ro, yo, marker='|',
2939+
**plot_kw))
29342940

29352941
if xlolims.any():
29362942
yo, _ = xywhere(y, right, xlolims & everymask)
@@ -2941,12 +2947,13 @@ def xywhere(xs, ys, mask):
29412947
marker = mlines.CARETLEFTBASE
29422948
else:
29432949
marker = mlines.CARETRIGHTBASE
2944-
caplines.extend(
2945-
self.plot(rightup, yup, ls='None', marker=marker,
2946-
**plot_kw))
2950+
caplines.append(
2951+
mlines.Line2D(rightup, yup, ls='None', marker=marker,
2952+
**plot_kw))
29472953
if capsize > 0:
29482954
xlo, ylo = xywhere(x, y, xlolims & everymask)
2949-
caplines.extend(self.plot(xlo, ylo, '|', **plot_kw))
2955+
caplines.append(mlines.Line2D(xlo, ylo, marker='|',
2956+
**plot_kw))
29502957

29512958
if xuplims.any():
29522959
yo, _ = xywhere(y, right, xuplims & everymask)
@@ -2957,12 +2964,13 @@ def xywhere(xs, ys, mask):
29572964
marker = mlines.CARETRIGHTBASE
29582965
else:
29592966
marker = mlines.CARETLEFTBASE
2960-
caplines.extend(
2961-
self.plot(leftlo, ylo, ls='None', marker=marker,
2962-
**plot_kw))
2967+
caplines.append(
2968+
mlines.Line2D(leftlo, ylo, ls='None', marker=marker,
2969+
**plot_kw))
29632970
if capsize > 0:
29642971
xup, yup = xywhere(x, y, xuplims & everymask)
2965-
caplines.extend(self.plot(xup, yup, '|', **plot_kw))
2972+
caplines.append(mlines.Line2D(xup, yup, marker='|',
2973+
**plot_kw))
29662974

29672975
if yerr is not None:
29682976
if (iterable(yerr) and len(yerr) == 2 and
@@ -2993,8 +3001,10 @@ def xywhere(xs, ys, mask):
29933001
lo, uo = xywhere(lower, upper, noylims & everymask)
29943002
barcols.append(self.vlines(xo, lo, uo, **lines_kw))
29953003
if capsize > 0:
2996-
caplines.extend(self.plot(xo, lo, '_', **plot_kw))
2997-
caplines.extend(self.plot(xo, uo, '_', **plot_kw))
3004+
caplines.append(mlines.Line2D(xo, lo, marker='_',
3005+
**plot_kw))
3006+
caplines.append(mlines.Line2D(xo, uo, marker='_',
3007+
**plot_kw))
29983008

29993009
if lolims.any():
30003010
xo, _ = xywhere(x, lower, lolims & everymask)
@@ -3005,12 +3015,13 @@ def xywhere(xs, ys, mask):
30053015
marker = mlines.CARETDOWNBASE
30063016
else:
30073017
marker = mlines.CARETUPBASE
3008-
caplines.extend(
3009-
self.plot(xup, upperup, ls='None', marker=marker,
3010-
**plot_kw))
3018+
caplines.append(
3019+
mlines.Line2D(xup, upperup, ls='None', marker=marker,
3020+
**plot_kw))
30113021
if capsize > 0:
30123022
xlo, ylo = xywhere(x, y, lolims & everymask)
3013-
caplines.extend(self.plot(xlo, ylo, 'k_', **plot_kw))
3023+
caplines.append(mlines.Line2D(xlo, ylo, marker='_',
3024+
**plot_kw))
30143025

30153026
if uplims.any():
30163027
xo, _ = xywhere(x, lower, uplims & everymask)
@@ -3021,20 +3032,25 @@ def xywhere(xs, ys, mask):
30213032
marker = mlines.CARETUPBASE
30223033
else:
30233034
marker = mlines.CARETDOWNBASE
3024-
caplines.extend(
3025-
self.plot(xlo, lowerlo, ls='None', marker=marker,
3026-
**plot_kw))
3035+
caplines.append(
3036+
mlines.Line2D(xlo, lowerlo, ls='None', marker=marker,
3037+
**plot_kw))
30273038
if capsize > 0:
30283039
xup, yup = xywhere(x, y, uplims & everymask)
3029-
caplines.extend(self.plot(xup, yup, 'k_', **plot_kw))
3040+
caplines.append(mlines.Line2D(xup, yup, marker='_',
3041+
**plot_kw))
3042+
for l in caplines:
3043+
self.add_line(l)
30303044

30313045
if not barsabove and plot_line:
3032-
l0, = self.plot(x, y, fmt, label='_nolegend_', **kwargs)
3046+
# in python3.5+ this can be simplified
3047+
eb_style = dict(base_style)
3048+
eb_style.update(**kwargs)
3049+
l0 = mlines.Line2D(x, y, **eb_style)
3050+
self.add_line(l0)
30333051

30343052
for l in barcols:
30353053
l.set_color(ecolor)
3036-
for l in caplines:
3037-
l.set_color(ecolor)
30383054

30393055
self.autoscale_view()
30403056
self._hold = holdstate

0 commit comments

Comments
 (0)