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

Skip to content

Commit 0543e9d

Browse files
committed
Re-group some bits of errorbar.
Move iterable checks before working on styling. In the styling section, the lines and caps dictionary modifications are intermixed, making them a bit confusing. Also do the same marker style removal from the cap style, which would normally be replaced later.
1 parent 149e7fb commit 0543e9d

File tree

1 file changed

+31
-25
lines changed

1 file changed

+31
-25
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3315,6 +3315,25 @@ def errorbar(self, x, y, yerr=None, xerr=None,
33153315

33163316
self._process_unit_info(xdata=x, ydata=y, kwargs=kwargs)
33173317

3318+
# Make sure all the args are iterable; use lists not arrays to preserve
3319+
# units.
3320+
if not np.iterable(x):
3321+
x = [x]
3322+
3323+
if not np.iterable(y):
3324+
y = [y]
3325+
3326+
if len(x) != len(y):
3327+
raise ValueError("'x' and 'y' must have the same size")
3328+
3329+
if xerr is not None:
3330+
if not np.iterable(xerr):
3331+
xerr = [xerr] * len(x)
3332+
3333+
if yerr is not None:
3334+
if not np.iterable(yerr):
3335+
yerr = [yerr] * len(y)
3336+
33183337
plot_line = (fmt.lower() != 'none')
33193338
label = kwargs.pop("label", None)
33203339

@@ -3339,24 +3358,6 @@ def errorbar(self, x, y, yerr=None, xerr=None,
33393358
base_style['color'] = 'C0'
33403359
if ecolor is None:
33413360
ecolor = base_style['color']
3342-
# make sure all the args are iterable; use lists not arrays to
3343-
# preserve units
3344-
if not np.iterable(x):
3345-
x = [x]
3346-
3347-
if not np.iterable(y):
3348-
y = [y]
3349-
3350-
if len(x) != len(y):
3351-
raise ValueError("'x' and 'y' must have the same size")
3352-
3353-
if xerr is not None:
3354-
if not np.iterable(xerr):
3355-
xerr = [xerr] * len(x)
3356-
3357-
if yerr is not None:
3358-
if not np.iterable(yerr):
3359-
yerr = [yerr] * len(y)
33603361

33613362
# make the style dict for the 'normal' plot line
33623363
plot_line_style = {
@@ -3366,9 +3367,14 @@ def errorbar(self, x, y, yerr=None, xerr=None,
33663367
kwargs['zorder'] + .1),
33673368
}
33683369

3369-
# make the style dict for the line collections (the bars)
3370+
# Make the style dict for the line collections (the bars), ejecting any
3371+
# marker information from format string.
33703372
eb_lines_style = dict(base_style)
33713373
eb_lines_style.pop('marker', None)
3374+
eb_lines_style.pop('markersize', None)
3375+
eb_lines_style.pop('markerfacecolor', None)
3376+
eb_lines_style.pop('markeredgewidth', None)
3377+
eb_lines_style.pop('markeredgecolor', None)
33723378
eb_lines_style.pop('linestyle', None)
33733379
eb_lines_style['color'] = ecolor
33743380

@@ -3381,14 +3387,14 @@ def errorbar(self, x, y, yerr=None, xerr=None,
33813387
if key in kwargs:
33823388
eb_lines_style[key] = kwargs[key]
33833389

3384-
# set up cap style dictionary
3390+
# Make the style dict for the caps, ejecting any marker information
3391+
# from format string.
33853392
eb_cap_style = dict(base_style)
3386-
# eject any marker information from format string
33873393
eb_cap_style.pop('marker', None)
3388-
eb_lines_style.pop('markerfacecolor', None)
3389-
eb_lines_style.pop('markeredgewidth', None)
3390-
eb_lines_style.pop('markeredgecolor', None)
3391-
eb_cap_style.pop('ls', None)
3394+
eb_cap_style.pop('markersize', None)
3395+
eb_cap_style.pop('markerfacecolor', None)
3396+
eb_cap_style.pop('markeredgewidth', None)
3397+
eb_cap_style.pop('markeredgecolor', None)
33923398
eb_cap_style['linestyle'] = 'none'
33933399
if capsize is None:
33943400
capsize = rcParams["errorbar.capsize"]

0 commit comments

Comments
 (0)