diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index c2549b8901a5..ac379dd2f965 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -2965,13 +2965,24 @@ def _bool_asarray_helper(d, expected): def xywhere(xs, ys, mask): """ - return xs[mask], ys[mask] where mask is True but xs and - ys are not arrays + Return xs[mask], ys[mask] where mask is True but xs and + ys are not arrays. + + If they are arrays, just return xs[mask] and ys[mask]. """ assert len(xs) == len(ys) assert len(xs) == len(mask) - xs = [thisx for thisx, b in zip(xs, mask) if b] - ys = [thisy for thisy, b in zip(ys, mask) if b] + + if isinstance(xs, np.ndarray): + xs = xs[mask] + else: + xs = [thisx for thisx, b in zip(xs, mask) if b] + + if isinstance(ys, np.ndarray): + ys = ys[mask] + else: + ys = [thisy for thisy, b in zip(ys, mask) if b] + return xs, ys def extract_err(err, data): @@ -3005,11 +3016,18 @@ def extract_err(err, data): if (len(err) != len(data) or np.size(fe) > 1): raise ValueError("err must be [ scalar | N, Nx1 " "or 2xN array-like ]") - # using list comps rather than arrays to preserve units - low = [thisx - thiserr for (thisx, thiserr) - in cbook.safezip(data, err)] - high = [thisx + thiserr for (thisx, thiserr) - in cbook.safezip(data, err)] + if isinstance(data, np.ndarray): + low = data - err + else: + # using list comps rather than arrays to preserve units + low = [thisx - thiserr for (thisx, thiserr) + in cbook.safezip(data, err)] + if isinstance(data, np.ndarray): + high = data + err + else: + # using list comps rather than arrays to preserve units + high = [thisx + thiserr for (thisx, thiserr) + in cbook.safezip(data, err)] return low, high if xerr is not None: