Skip to content

Commit 6da2d60

Browse files
committed
WIP
1 parent e789a70 commit 6da2d60

File tree

1 file changed

+44
-35
lines changed

1 file changed

+44
-35
lines changed

lib/matplotlib/axes/_axes.py

+44-35
Original file line numberDiff line numberDiff line change
@@ -2791,9 +2791,26 @@ def errorbar(self, x, y, yerr=None, xerr=None,
27912791
warnings.warn(msg, mplDeprecation, stacklevel=1)
27922792

27932793
plot_line = (fmt.lower() != 'none')
2794-
27952794
label = kwargs.pop("label", None)
27962795

2796+
fmt_style_kwargs = {k: v for k, v in
2797+
zip(('linestyle', 'marker', 'color'),
2798+
_process_plot_format(fmt)) if v is not None}
2799+
2800+
if ('color' in kwargs or 'color' in fmt_style_kwargs or
2801+
ecolor is not None):
2802+
base_style = {}
2803+
else:
2804+
base_style = six.next(self._get_lines.prop_cycler)
2805+
2806+
base_style['label'] = '_nolegend_'
2807+
base_style['color'] = kwargs.pop('color')
2808+
base_style.update(fmt_style_kwargs)
2809+
if ecolor is not None:
2810+
base_style['color'] = ecolor
2811+
if 'color' not in base_style:
2812+
base_style['color'] = 'b'
2813+
27972814
# make sure all the args are iterable; use lists not arrays to
27982815
# preserve units
27992816
if not iterable(x):
@@ -2815,12 +2832,15 @@ def errorbar(self, x, y, yerr=None, xerr=None,
28152832
# Instead of using zorder, the line plot is being added
28162833
# either here, or after all the errorbar plot elements.
28172834
if barsabove and plot_line:
2818-
l0, = self.plot(x, y, fmt, label="_nolegend_", **kwargs)
2835+
# in python3.5+ this can be simplified
2836+
eb_style = dict(base_style)
2837+
eb_style.update(**kwargs)
2838+
l0, = self.plot(x, y, **eb_style)
28192839

28202840
barcols = []
28212841
caplines = []
28222842

2823-
lines_kw = {'label': '_nolegend_'}
2843+
lines_kw = dict(base_style)
28242844
if elinewidth:
28252845
lines_kw['linewidth'] = elinewidth
28262846
else:
@@ -2832,25 +2852,16 @@ def errorbar(self, x, y, yerr=None, xerr=None,
28322852
lines_kw[key] = kwargs[key]
28332853

28342854
# arrays fine here, they are booleans and hence not units
2835-
if not iterable(lolims):
2836-
lolims = np.asarray([lolims] * len(x), bool)
2837-
else:
2838-
lolims = np.asarray(lolims, bool)
2839-
2840-
if not iterable(uplims):
2841-
uplims = np.array([uplims] * len(x), bool)
2842-
else:
2843-
uplims = np.asarray(uplims, bool)
2855+
def _bool_asarray_helper(d, expected):
2856+
if not iterable(d):
2857+
lolims = np.asarray([d] * expected, bool)
2858+
else:
2859+
lolims = np.asarray(lolims, bool)
28442860

2845-
if not iterable(xlolims):
2846-
xlolims = np.array([xlolims] * len(x), bool)
2847-
else:
2848-
xlolims = np.asarray(xlolims, bool)
2849-
2850-
if not iterable(xuplims):
2851-
xuplims = np.array([xuplims] * len(x), bool)
2852-
else:
2853-
xuplims = np.asarray(xuplims, bool)
2861+
lolims = _bool_asarray_helper(lolims, len(x))
2862+
uplims = _bool_asarray_helper(uplims, len(x))
2863+
xlolims = _bool_asarray_helper(xlolims, len(x))
2864+
xuplims = _bool_asarray_helper(xuplims, len(x))
28542865

28552866
everymask = np.arange(len(x)) % errorevery == 0
28562867

@@ -2865,7 +2876,11 @@ def xywhere(xs, ys, mask):
28652876
ys = [thisy for thisy, b in zip(ys, mask) if b]
28662877
return xs, ys
28672878

2868-
plot_kw = {'label': '_nolegend_'}
2879+
plot_kw = dict(base_style)
2880+
# eject any marker information from format string
2881+
plot_kw.pop('marker', None)
2882+
plot_kw.pop('ls', None)
2883+
plot_kw.pop('linestyle', None)
28692884
if capsize is None:
28702885
capsize = rcParams["errorbar.capsize"]
28712886
if capsize > 0:
@@ -2885,7 +2900,7 @@ def xywhere(xs, ys, mask):
28852900

28862901
if xerr is not None:
28872902
if (iterable(xerr) and len(xerr) == 2 and
2888-
iterable(xerr[0]) and iterable(xerr[1])):
2903+
iterable(xerr[0]) and iterable(xerr[1])):
28892904
# using list comps rather than arrays to preserve units
28902905
left = [thisx - thiserr for (thisx, thiserr)
28912906
in cbook.safezip(x, xerr[0])]
@@ -2914,8 +2929,8 @@ def xywhere(xs, ys, mask):
29142929
lo, ro = xywhere(left, right, noxlims & everymask)
29152930
barcols.append(self.hlines(yo, lo, ro, **lines_kw))
29162931
if capsize > 0:
2917-
caplines.extend(self.plot(lo, yo, 'k|', **plot_kw))
2918-
caplines.extend(self.plot(ro, yo, 'k|', **plot_kw))
2932+
caplines.extend(self.plot(lo, yo, '|', **plot_kw))
2933+
caplines.extend(self.plot(ro, yo, '|', **plot_kw))
29192934

29202935
if xlolims.any():
29212936
yo, _ = xywhere(y, right, xlolims & everymask)
@@ -2931,7 +2946,7 @@ def xywhere(xs, ys, mask):
29312946
**plot_kw))
29322947
if capsize > 0:
29332948
xlo, ylo = xywhere(x, y, xlolims & everymask)
2934-
caplines.extend(self.plot(xlo, ylo, 'k|', **plot_kw))
2949+
caplines.extend(self.plot(xlo, ylo, '|', **plot_kw))
29352950

29362951
if xuplims.any():
29372952
yo, _ = xywhere(y, right, xuplims & everymask)
@@ -2947,7 +2962,7 @@ def xywhere(xs, ys, mask):
29472962
**plot_kw))
29482963
if capsize > 0:
29492964
xup, yup = xywhere(x, y, xuplims & everymask)
2950-
caplines.extend(self.plot(xup, yup, 'k|', **plot_kw))
2965+
caplines.extend(self.plot(xup, yup, '|', **plot_kw))
29512966

29522967
if yerr is not None:
29532968
if (iterable(yerr) and len(yerr) == 2 and
@@ -2978,8 +2993,8 @@ def xywhere(xs, ys, mask):
29782993
lo, uo = xywhere(lower, upper, noylims & everymask)
29792994
barcols.append(self.vlines(xo, lo, uo, **lines_kw))
29802995
if capsize > 0:
2981-
caplines.extend(self.plot(xo, lo, 'k_', **plot_kw))
2982-
caplines.extend(self.plot(xo, uo, 'k_', **plot_kw))
2996+
caplines.extend(self.plot(xo, lo, '_', **plot_kw))
2997+
caplines.extend(self.plot(xo, uo, '_', **plot_kw))
29832998

29842999
if lolims.any():
29853000
xo, _ = xywhere(x, lower, lolims & everymask)
@@ -3016,12 +3031,6 @@ def xywhere(xs, ys, mask):
30163031
if not barsabove and plot_line:
30173032
l0, = self.plot(x, y, fmt, label='_nolegend_', **kwargs)
30183033

3019-
if ecolor is None:
3020-
if l0 is None and 'color' in self._get_lines._prop_keys:
3021-
ecolor = six.next(self._get_lines.prop_cycler)['color']
3022-
else:
3023-
ecolor = l0.get_color()
3024-
30253034
for l in barcols:
30263035
l.set_color(ecolor)
30273036
for l in caplines:

0 commit comments

Comments
 (0)