|
16 | 16 |
|
17 | 17 | import matplotlib.cbook as cbook
|
18 | 18 | from matplotlib.cbook import (mplDeprecation, STEP_LOOKUP_MAP,
|
19 |
| - iterable, is_string_like) |
| 19 | + iterable, is_string_like, |
| 20 | + safe_first_element) |
20 | 21 | import matplotlib.collections as mcoll
|
21 | 22 | import matplotlib.colors as mcolors
|
22 | 23 | import matplotlib.contour as mcontour
|
@@ -2904,29 +2905,44 @@ def xywhere(xs, ys, mask):
|
2904 | 2905 | if key in kwargs:
|
2905 | 2906 | plot_kw[key] = kwargs[key]
|
2906 | 2907 |
|
2907 |
| - if xerr is not None: |
2908 |
| - if (iterable(xerr) and len(xerr) == 2 and |
2909 |
| - iterable(xerr[0]) and iterable(xerr[1])): |
2910 |
| - # using list comps rather than arrays to preserve units |
2911 |
| - left = [thisx - thiserr for (thisx, thiserr) |
2912 |
| - in cbook.safezip(x, xerr[0])] |
2913 |
| - right = [thisx + thiserr for (thisx, thiserr) |
2914 |
| - in cbook.safezip(x, xerr[1])] |
2915 |
| - else: |
2916 |
| - # Check if xerr is scalar or symmetric. Asymmetric is handled |
2917 |
| - # above. This prevents Nx2 arrays from accidentally |
2918 |
| - # being accepted, when the user meant the 2xN transpose. |
2919 |
| - # special case for empty lists |
2920 |
| - if len(xerr) > 1 and not ((len(xerr) == len(x) and not ( |
2921 |
| - iterable(xerr[0]) and len(xerr[0]) > 1))): |
2922 |
| - raise ValueError("xerr must be a scalar, the same " |
| 2908 | + def extract_err(err, data): |
| 2909 | + '''private function to compute error bars |
| 2910 | +
|
| 2911 | + Parameters |
| 2912 | + ---------- |
| 2913 | + err : iterable |
| 2914 | + xerr or yerr from errorbar |
| 2915 | + data : iterable |
| 2916 | + x or y from errorbar |
| 2917 | + ''' |
| 2918 | + if (iterable(err) and len(err) == 2): |
| 2919 | + a, b = err |
| 2920 | + if iterable(a) and iterable(b): |
| 2921 | + # using list comps rather than arrays to preserve units |
| 2922 | + low = [thisx - thiserr for (thisx, thiserr) |
| 2923 | + in cbook.safezip(data, a)] |
| 2924 | + high = [thisx + thiserr for (thisx, thiserr) |
| 2925 | + in cbook.safezip(data, b)] |
| 2926 | + return low, high |
| 2927 | + # Check if xerr is scalar or symmetric. Asymmetric is handled |
| 2928 | + # above. This prevents Nx2 arrays from accidentally |
| 2929 | + # being accepted, when the user meant the 2xN transpose. |
| 2930 | + # special case for empty lists |
| 2931 | + if len(err) > 1: |
| 2932 | + fe = safe_first_element(err) |
| 2933 | + if not ((len(err) == len(data) and not (iterable(fe) and |
| 2934 | + len(fe) > 1))): |
| 2935 | + raise ValueError("err must be a scalar, the same " |
2923 | 2936 | "dimensions as x, or 2xN.")
|
2924 |
| - # using list comps rather than arrays to preserve units |
2925 |
| - left = [thisx - thiserr for (thisx, thiserr) |
2926 |
| - in cbook.safezip(x, xerr)] |
2927 |
| - right = [thisx + thiserr for (thisx, thiserr) |
2928 |
| - in cbook.safezip(x, xerr)] |
| 2937 | + # using list comps rather than arrays to preserve units |
| 2938 | + low = [thisx - thiserr for (thisx, thiserr) |
| 2939 | + in cbook.safezip(data, err)] |
| 2940 | + high = [thisx + thiserr for (thisx, thiserr) |
| 2941 | + in cbook.safezip(data, err)] |
| 2942 | + return low, high |
2929 | 2943 |
|
| 2944 | + if xerr is not None: |
| 2945 | + left, right = extract_err(xerr, x) |
2930 | 2946 | # select points without upper/lower limits in x and
|
2931 | 2947 | # draw normal errorbars for these points
|
2932 | 2948 | noxlims = ~(xlolims | xuplims)
|
@@ -2971,25 +2987,7 @@ def xywhere(xs, ys, mask):
|
2971 | 2987 | caplines.extend(self.plot(xup, yup, 'k|', **plot_kw))
|
2972 | 2988 |
|
2973 | 2989 | if yerr is not None:
|
2974 |
| - if (iterable(yerr) and len(yerr) == 2 and |
2975 |
| - iterable(yerr[0]) and iterable(yerr[1])): |
2976 |
| - # using list comps rather than arrays to preserve units |
2977 |
| - lower = [thisy - thiserr for (thisy, thiserr) |
2978 |
| - in cbook.safezip(y, yerr[0])] |
2979 |
| - upper = [thisy + thiserr for (thisy, thiserr) |
2980 |
| - in cbook.safezip(y, yerr[1])] |
2981 |
| - else: |
2982 |
| - # Check for scalar or symmetric, as in xerr. |
2983 |
| - if len(yerr) > 1 and not ((len(yerr) == len(y) and not ( |
2984 |
| - iterable(yerr[0]) and len(yerr[0]) > 1))): |
2985 |
| - raise ValueError("yerr must be a scalar, the same " |
2986 |
| - "dimensions as y, or 2xN.") |
2987 |
| - # using list comps rather than arrays to preserve units |
2988 |
| - lower = [thisy - thiserr for (thisy, thiserr) |
2989 |
| - in cbook.safezip(y, yerr)] |
2990 |
| - upper = [thisy + thiserr for (thisy, thiserr) |
2991 |
| - in cbook.safezip(y, yerr)] |
2992 |
| - |
| 2990 | + lower, upper = extract_err(yerr, y) |
2993 | 2991 | # select points without upper/lower limits in y and
|
2994 | 2992 | # draw normal errorbars for these points
|
2995 | 2993 | noylims = ~(lolims | uplims)
|
|
0 commit comments