Skip to content

Commit a953914

Browse files
committed
Make errorbar's main Line2D closer to plot.
We can't directly use `self.plot` or `self._get_lines` because they would do `self._process_unit_info` and/or *data* keyword argument processing.
1 parent 353864a commit a953914

File tree

2 files changed

+46
-58
lines changed

2 files changed

+46
-58
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 21 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3334,39 +3334,35 @@ def errorbar(self, x, y, yerr=None, xerr=None,
33343334
if not np.iterable(yerr):
33353335
yerr = [yerr] * len(y)
33363336

3337-
plot_line = (fmt.lower() != 'none')
33383337
label = kwargs.pop("label", None)
3338+
kwargs['label'] = '_nolegend_'
3339+
3340+
# Create the main line and determine overall kwargs for child artists.
3341+
# We avoid calling self.plot() directly, or self._get_lines(), because
3342+
# that would call self._process_unit_info again, and do other indirect
3343+
# data processing.
3344+
(data_line, base_style), = self._get_lines._plot_args(
3345+
(x, y) if fmt == '' else (x, y, fmt), kwargs, return_kwargs=True)
3346+
3347+
# Do this after creating `data_line` to avoid modifying `base_style`.
3348+
if barsabove:
3349+
data_line.set_zorder(kwargs['zorder'] - .1)
3350+
else:
3351+
data_line.set_zorder(kwargs['zorder'] + .1)
33393352

3340-
if fmt == '':
3341-
fmt_style_kwargs = {}
3353+
# Add line to plot, or throw it away and use it to determine kwargs.
3354+
if fmt.lower() != 'none':
3355+
self.add_line(data_line)
33423356
else:
3343-
fmt_style_kwargs = {k: v for k, v in
3344-
zip(('linestyle', 'marker', 'color'),
3345-
_process_plot_format(fmt))
3346-
if v is not None}
3347-
if fmt == 'none':
3348-
# Remove alpha=0 color that _process_plot_format returns
3349-
fmt_style_kwargs.pop('color')
3350-
3351-
base_style = self._get_lines._getdefaults(
3352-
set(), {**fmt_style_kwargs, **kwargs})
3353-
if 'color' in kwargs:
3354-
base_style['color'] = kwargs.pop('color')
3355-
base_style['label'] = '_nolegend_'
3356-
base_style.update(fmt_style_kwargs)
3357+
data_line = None
3358+
# Remove alpha=0 color that _process_plot_format returns.
3359+
base_style.pop('color')
3360+
33573361
if 'color' not in base_style:
33583362
base_style['color'] = 'C0'
33593363
if ecolor is None:
33603364
ecolor = base_style['color']
33613365

3362-
# make the style dict for the 'normal' plot line
3363-
plot_line_style = {
3364-
**base_style,
3365-
**kwargs,
3366-
'zorder': (kwargs['zorder'] - .1 if barsabove else
3367-
kwargs['zorder'] + .1),
3368-
}
3369-
33703366
# Make the style dict for the line collections (the bars), ejecting any
33713367
# marker information from format string.
33723368
eb_lines_style = dict(base_style)
@@ -3411,11 +3407,6 @@ def errorbar(self, x, y, yerr=None, xerr=None,
34113407
eb_cap_style[key] = kwargs[key]
34123408
eb_cap_style['color'] = ecolor
34133409

3414-
data_line = None
3415-
if plot_line:
3416-
data_line = mlines.Line2D(x, y, **plot_line_style)
3417-
self.add_line(data_line)
3418-
34193410
barcols = []
34203411
caplines = []
34213412

lib/mpl_toolkits/mplot3d/axes3d.py

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3026,6 +3026,9 @@ def errorbar(self, x, y, z, zerr=None, yerr=None, xerr=None, fmt='',
30263026
"""
30273027
had_data = self.has_data()
30283028

3029+
if 'zorder' not in kwargs:
3030+
kwargs['zorder'] = 2
3031+
30293032
try:
30303033
offset, errorevery = errorevery
30313034
except TypeError:
@@ -3046,42 +3049,36 @@ def errorbar(self, x, y, z, zerr=None, yerr=None, xerr=None, fmt='',
30463049
if not len(x) == len(y) == len(z):
30473050
raise ValueError("'x', 'y', and 'z' must have the same size")
30483051

3049-
plot_line = (fmt.lower() != 'none')
30503052
label = kwargs.pop("label", None)
3053+
kwargs['label'] = '_nolegend_'
3054+
3055+
# Create the main line and determine overall kwargs for child artists.
3056+
# We avoid calling self.plot() directly, or self._get_lines(), because
3057+
# that would call self._process_unit_info again, and do other indirect
3058+
# data processing.
3059+
(data_line, base_style), = self._get_lines._plot_args(
3060+
(x, y) if fmt == '' else (x, y, fmt), kwargs, return_kwargs=True)
3061+
art3d.line_2d_to_3d(data_line, zs=z)
3062+
3063+
# Do this after creating `data_line` to avoid modifying `base_style`.
3064+
if barsabove:
3065+
data_line.set_zorder(kwargs['zorder'] - .1)
3066+
else:
3067+
data_line.set_zorder(kwargs['zorder'] + .1)
30513068

3052-
if fmt == '':
3053-
fmt_style_kwargs = {}
3069+
# Add line to plot, or throw it away and use it to determine kwargs.
3070+
if fmt.lower() != 'none':
3071+
self.add_line(data_line)
30543072
else:
3055-
fmt_style_kwargs = {k: v for k, v in
3056-
zip(('linestyle', 'marker', 'color'),
3057-
_process_plot_format(fmt))
3058-
if v is not None}
3059-
3060-
if fmt == 'none':
3061-
# Remove alpha=0 color that _process_plot_format returns
3062-
fmt_style_kwargs.pop('color')
3063-
3064-
base_style = self._get_lines._getdefaults(
3065-
set(), {**fmt_style_kwargs, **kwargs})
3066-
if 'color' in kwargs:
3067-
base_style['color'] = kwargs.pop('color')
3068-
base_style['label'] = '_nolegend_'
3069-
base_style.update(fmt_style_kwargs)
3073+
data_line = None
3074+
# Remove alpha=0 color that _process_plot_format returns.
3075+
base_style.pop('color')
3076+
30703077
if 'color' not in base_style:
30713078
base_style['color'] = 'C0'
30723079
if ecolor is None:
30733080
ecolor = base_style['color']
30743081

3075-
# make the style dict for the 'normal' plot line
3076-
if 'zorder' not in kwargs:
3077-
kwargs['zorder'] = 2
3078-
plot_line_style = {
3079-
**base_style,
3080-
**kwargs,
3081-
'zorder': (kwargs['zorder'] - .1 if barsabove else
3082-
kwargs['zorder'] + .1),
3083-
}
3084-
30853082
# Make the style dict for the line collections (the bars), ejecting any
30863083
# marker information from format string.
30873084
eb_lines_style = dict(base_style)

0 commit comments

Comments
 (0)