Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a61a034

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 1ee4d65 commit a61a034

File tree

1 file changed

+21
-30
lines changed

1 file changed

+21
-30
lines changed

lib/matplotlib/axes/_axes.py

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

3285-
plot_line = (fmt.lower() != 'none')
32863285
label = kwargs.pop("label", None)
3286+
kwargs['label'] = '_nolegend_'
3287+
3288+
# Create the main line and determine overall kwargs for child artists.
3289+
# We avoid calling self.plot() directly, or self._get_lines(), because
3290+
# that would call self._process_unit_info again, and do other indirect
3291+
# data processing.
3292+
(data_line, base_style), = self._get_lines._plot_args(
3293+
(x, y) if fmt == '' else (x, y, fmt), kwargs, return_kwargs=True)
3294+
3295+
# Do this after creating `data_line` to avoid modifying `base_style`.
3296+
if barsabove:
3297+
data_line.set_zorder(kwargs['zorder'] - .1)
3298+
else:
3299+
data_line.set_zorder(kwargs['zorder'] + .1)
32873300

3288-
if fmt == '':
3289-
fmt_style_kwargs = {}
3301+
# Add line to plot, or throw it away and use it to determine kwargs.
3302+
if fmt.lower() != 'none':
3303+
self.add_line(data_line)
32903304
else:
3291-
fmt_style_kwargs = {k: v for k, v in
3292-
zip(('linestyle', 'marker', 'color'),
3293-
_process_plot_format(fmt))
3294-
if v is not None}
3295-
if fmt == 'none':
3296-
# Remove alpha=0 color that _process_plot_format returns
3297-
fmt_style_kwargs.pop('color')
3298-
3299-
base_style = self._get_lines._getdefaults(
3300-
set(), {**fmt_style_kwargs, **kwargs})
3301-
if 'color' in kwargs:
3302-
base_style['color'] = kwargs.pop('color')
3303-
base_style['label'] = '_nolegend_'
3304-
base_style.update(fmt_style_kwargs)
3305+
data_line = None
3306+
# Remove alpha=0 color that _process_plot_format returns.
3307+
base_style.pop('color')
3308+
33053309
if 'color' not in base_style:
33063310
base_style['color'] = 'C0'
33073311
if ecolor is None:
33083312
ecolor = base_style['color']
33093313

3310-
# make the style dict for the 'normal' plot line
3311-
plot_line_style = {
3312-
**base_style,
3313-
**kwargs,
3314-
'zorder': (kwargs['zorder'] - .1 if barsabove else
3315-
kwargs['zorder'] + .1),
3316-
}
3317-
33183314
# Make the style dict for the line collections (the bars), ejecting any
33193315
# marker information from format string.
33203316
eb_lines_style = dict(base_style)
@@ -3359,11 +3355,6 @@ def errorbar(self, x, y, yerr=None, xerr=None,
33593355
eb_cap_style[key] = kwargs[key]
33603356
eb_cap_style['color'] = ecolor
33613357

3362-
data_line = None
3363-
if plot_line:
3364-
data_line = mlines.Line2D(x, y, **plot_line_style)
3365-
self.add_line(data_line)
3366-
33673358
barcols = []
33683359
caplines = []
33693360

0 commit comments

Comments
 (0)