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

Skip to content

Commit 1614dbb

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 780bfab commit 1614dbb

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
@@ -3101,6 +3102,35 @@ def errorbar(self, x, y, z, zerr=None, yerr=None, xerr=None, fmt='',
31013102
"""
31023103
had_data = self.has_data()
31033104

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

@@ -3130,33 +3160,25 @@ def errorbar(self, x, y, z, zerr=None, yerr=None, xerr=None, fmt='',
31303160
if ecolor is None:
31313161
ecolor = base_style['color']
31323162

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

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

31613183
if elinewidth:
31623184
eb_lines_style['linewidth'] = elinewidth
@@ -3167,35 +3189,21 @@ def errorbar(self, x, y, z, zerr=None, yerr=None, xerr=None, fmt='',
31673189
if key in kwargs:
31683190
eb_lines_style[key] = kwargs[key]
31693191

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

3202+
data_line = None
31843203
if plot_line:
31853204
data_line = art3d.Line3D(x, y, z, **plot_line_style)
31863205
self.add_line(data_line)
31873206

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

0 commit comments

Comments
 (0)