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

Skip to content

Commit 7ec93d7

Browse files
committed
Sync some things from 2D errorbar to 3D.
Namely, kwarg normalization, unit info processing, and adding a default `data_line`, so it works when `fmt='none'`. Move iterable checks before working on styling. Also, move `errorevery` checks to a similar location as the 2D code.
1 parent 50104a7 commit 7ec93d7

File tree

2 files changed

+46
-38
lines changed

2 files changed

+46
-38
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3384,7 +3384,7 @@ def errorbar(self, x, y, yerr=None, xerr=None,
33843384
if key in kwargs:
33853385
eb_lines_style[key] = kwargs[key]
33863386

3387-
# Make the style dict for the caps.
3387+
# Make the style dict for caps (the "hats").
33883388
eb_cap_style = {**base_style, 'linestyle': 'none'}
33893389
if capsize is None:
33903390
capsize = rcParams["errorbar.capsize"]

lib/mpl_toolkits/mplot3d/axes3d.py

Lines changed: 45 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import matplotlib.axes as maxes
2323
import matplotlib.collections as mcoll
2424
import matplotlib.colors as mcolors
25+
import matplotlib.lines as mlines
2526
import matplotlib.scale as mscale
2627
import matplotlib.container as mcontainer
2728
import matplotlib.transforms as mtransforms
@@ -3099,6 +3100,35 @@ def errorbar(self, x, y, z, zerr=None, yerr=None, xerr=None, fmt='',
30993100
"""
31003101
had_data = self.has_data()
31013102

3103+
kwargs = cbook.normalize_kwargs(kwargs, mlines.Line2D)
3104+
# anything that comes in as 'None', drop so the default thing
3105+
# happens down stream
3106+
kwargs = {k: v for k, v in kwargs.items() if v is not None}
3107+
kwargs.setdefault('zorder', 2)
3108+
3109+
try:
3110+
offset, errorevery = errorevery
3111+
except TypeError:
3112+
offset = 0
3113+
3114+
if errorevery < 1 or int(errorevery) != errorevery:
3115+
raise ValueError(
3116+
'errorevery must be positive integer or tuple of integers')
3117+
if int(offset) != offset:
3118+
raise ValueError("errorevery's starting index must be an integer")
3119+
3120+
self._process_unit_info([("x", x), ("y", y), ("z", z)], kwargs,
3121+
convert=False)
3122+
3123+
# make sure all the args are iterable; use lists not arrays to
3124+
# preserve units
3125+
x = x if np.iterable(x) else [x]
3126+
y = y if np.iterable(y) else [y]
3127+
z = z if np.iterable(z) else [z]
3128+
3129+
if not len(x) == len(y) == len(z):
3130+
raise ValueError("'x', 'y', and 'z' must have the same size")
3131+
31023132
plot_line = (fmt.lower() != 'none')
31033133
label = kwargs.pop("label", None)
31043134

@@ -3128,33 +3158,25 @@ def errorbar(self, x, y, z, zerr=None, yerr=None, xerr=None, fmt='',
31283158
if ecolor is None:
31293159
ecolor = base_style['color']
31303160

3131-
# make sure all the args are iterable; use lists not arrays to
3132-
# preserve units
3133-
x = x if np.iterable(x) else [x]
3134-
y = y if np.iterable(y) else [y]
3135-
z = z if np.iterable(z) else [z]
3136-
3137-
if not len(x) == len(y) == len(z):
3138-
raise ValueError("'x', 'y', and 'z' must have the same size")
3139-
31403161
# make the style dict for the 'normal' plot line
3141-
if 'zorder' not in kwargs:
3142-
kwargs['zorder'] = 2
31433162
plot_line_style = {
31443163
**base_style,
31453164
**kwargs,
31463165
'zorder': (kwargs['zorder'] - .1 if barsabove else
31473166
kwargs['zorder'] + .1),
31483167
}
31493168

3150-
# make the style dict for the line collections (the bars)
3151-
eb_lines_style = dict(base_style)
3152-
eb_lines_style.pop('marker', None)
3153-
eb_lines_style.pop('markerfacecolor', None)
3154-
eb_lines_style.pop('markeredgewidth', None)
3155-
eb_lines_style.pop('markeredgecolor', None)
3156-
eb_lines_style.pop('linestyle', None)
3157-
eb_lines_style['color'] = ecolor
3169+
# Eject any marker information from line format string, as it's not
3170+
# needed for bars or caps.
3171+
base_style.pop('marker', None)
3172+
base_style.pop('markersize', None)
3173+
base_style.pop('markerfacecolor', None)
3174+
base_style.pop('markeredgewidth', None)
3175+
base_style.pop('markeredgecolor', None)
3176+
base_style.pop('linestyle', None)
3177+
3178+
# Make the style dict for the line collections (the bars).
3179+
eb_lines_style = {**base_style, 'color': ecolor}
31583180

31593181
if elinewidth:
31603182
eb_lines_style['linewidth'] = elinewidth
@@ -3165,35 +3187,21 @@ def errorbar(self, x, y, z, zerr=None, yerr=None, xerr=None, fmt='',
31653187
if key in kwargs:
31663188
eb_lines_style[key] = kwargs[key]
31673189

3168-
# make the style dict for cap collections (the "hats")
3169-
eb_cap_style = dict(base_style)
3170-
# eject any marker information from format string
3171-
eb_cap_style.pop('marker', None)
3172-
eb_cap_style.pop('ls', None)
3173-
eb_cap_style['linestyle'] = 'none'
3190+
# Make the style dict for caps (the "hats").
3191+
eb_cap_style = {**base_style, 'linestyle': 'none'}
31743192
if capsize is None:
3175-
capsize = kwargs.pop('capsize', rcParams["errorbar.capsize"])
3193+
capsize = rcParams["errorbar.capsize"]
31763194
if capsize > 0:
31773195
eb_cap_style['markersize'] = 2. * capsize
31783196
if capthick is not None:
31793197
eb_cap_style['markeredgewidth'] = capthick
31803198
eb_cap_style['color'] = ecolor
31813199

3200+
data_line = None
31823201
if plot_line:
31833202
data_line = art3d.Line3D(x, y, z, **plot_line_style)
31843203
self.add_line(data_line)
31853204

3186-
try:
3187-
offset, errorevery = errorevery
3188-
except TypeError:
3189-
offset = 0
3190-
3191-
if errorevery < 1 or int(errorevery) != errorevery:
3192-
raise ValueError(
3193-
'errorevery must be positive integer or tuple of integers')
3194-
if int(offset) != offset:
3195-
raise ValueError("errorevery's starting index must be an integer")
3196-
31973205
everymask = np.zeros(len(x), bool)
31983206
everymask[offset::errorevery] = True
31993207

0 commit comments

Comments
 (0)