|
15 | 15 |
|
16 | 16 | import matplotlib.cbook as cbook
|
17 | 17 | from matplotlib.cbook import (mplDeprecation, STEP_LOOKUP_MAP,
|
18 |
| - iterable, is_string_like) |
| 18 | + iterable, is_string_like, |
| 19 | + safe_first_element) |
19 | 20 | import matplotlib.collections as mcoll
|
20 | 21 | import matplotlib.colors as mcolors
|
21 | 22 | import matplotlib.contour as mcontour
|
@@ -2890,29 +2891,44 @@ def xywhere(xs, ys, mask):
|
2890 | 2891 | if key in kwargs:
|
2891 | 2892 | plot_kw[key] = kwargs[key]
|
2892 | 2893 |
|
2893 |
| - if xerr is not None: |
2894 |
| - if (iterable(xerr) and len(xerr) == 2 and |
2895 |
| - iterable(xerr[0]) and iterable(xerr[1])): |
2896 |
| - # using list comps rather than arrays to preserve units |
2897 |
| - left = [thisx - thiserr for (thisx, thiserr) |
2898 |
| - in cbook.safezip(x, xerr[0])] |
2899 |
| - right = [thisx + thiserr for (thisx, thiserr) |
2900 |
| - in cbook.safezip(x, xerr[1])] |
2901 |
| - else: |
2902 |
| - # Check if xerr is scalar or symmetric. Asymmetric is handled |
2903 |
| - # above. This prevents Nx2 arrays from accidentally |
2904 |
| - # being accepted, when the user meant the 2xN transpose. |
2905 |
| - # special case for empty lists |
2906 |
| - if len(xerr) > 1 and not ((len(xerr) == len(x) and not ( |
2907 |
| - iterable(xerr[0]) and len(xerr[0]) > 1))): |
2908 |
| - raise ValueError("xerr must be a scalar, the same " |
| 2894 | + def extract_err(err, data): |
| 2895 | + '''private function to compute error bars |
| 2896 | +
|
| 2897 | + Parameters |
| 2898 | + ---------- |
| 2899 | + err : iterable |
| 2900 | + xerr or yerr from errorbar |
| 2901 | + data : iterable |
| 2902 | + x or y from errorbar |
| 2903 | + ''' |
| 2904 | + if (iterable(err) and len(err) == 2): |
| 2905 | + a, b = err |
| 2906 | + if iterable(a) and iterable(b): |
| 2907 | + # using list comps rather than arrays to preserve units |
| 2908 | + low = [thisx - thiserr for (thisx, thiserr) |
| 2909 | + in cbook.safezip(data, a)] |
| 2910 | + high = [thisx + thiserr for (thisx, thiserr) |
| 2911 | + in cbook.safezip(data, b)] |
| 2912 | + return low, high |
| 2913 | + # Check if xerr is scalar or symmetric. Asymmetric is handled |
| 2914 | + # above. This prevents Nx2 arrays from accidentally |
| 2915 | + # being accepted, when the user meant the 2xN transpose. |
| 2916 | + # special case for empty lists |
| 2917 | + if len(err) > 1: |
| 2918 | + fe = safe_first_element(err) |
| 2919 | + if not ((len(err) == len(data) and not (iterable(fe) and |
| 2920 | + len(fe) > 1))): |
| 2921 | + raise ValueError("err must be a scalar, the same " |
2909 | 2922 | "dimensions as x, or 2xN.")
|
2910 |
| - # using list comps rather than arrays to preserve units |
2911 |
| - left = [thisx - thiserr for (thisx, thiserr) |
2912 |
| - in cbook.safezip(x, xerr)] |
2913 |
| - right = [thisx + thiserr for (thisx, thiserr) |
2914 |
| - in cbook.safezip(x, xerr)] |
| 2923 | + # using list comps rather than arrays to preserve units |
| 2924 | + low = [thisx - thiserr for (thisx, thiserr) |
| 2925 | + in cbook.safezip(data, err)] |
| 2926 | + high = [thisx + thiserr for (thisx, thiserr) |
| 2927 | + in cbook.safezip(data, err)] |
| 2928 | + return low, high |
2915 | 2929 |
|
| 2930 | + if xerr is not None: |
| 2931 | + left, right = extract_err(xerr, x) |
2916 | 2932 | # select points without upper/lower limits in x and
|
2917 | 2933 | # draw normal errorbars for these points
|
2918 | 2934 | noxlims = ~(xlolims | xuplims)
|
@@ -2957,25 +2973,7 @@ def xywhere(xs, ys, mask):
|
2957 | 2973 | caplines.extend(self.plot(xup, yup, 'k|', **plot_kw))
|
2958 | 2974 |
|
2959 | 2975 | if yerr is not None:
|
2960 |
| - if (iterable(yerr) and len(yerr) == 2 and |
2961 |
| - iterable(yerr[0]) and iterable(yerr[1])): |
2962 |
| - # using list comps rather than arrays to preserve units |
2963 |
| - lower = [thisy - thiserr for (thisy, thiserr) |
2964 |
| - in cbook.safezip(y, yerr[0])] |
2965 |
| - upper = [thisy + thiserr for (thisy, thiserr) |
2966 |
| - in cbook.safezip(y, yerr[1])] |
2967 |
| - else: |
2968 |
| - # Check for scalar or symmetric, as in xerr. |
2969 |
| - if len(yerr) > 1 and not ((len(yerr) == len(y) and not ( |
2970 |
| - iterable(yerr[0]) and len(yerr[0]) > 1))): |
2971 |
| - raise ValueError("yerr must be a scalar, the same " |
2972 |
| - "dimensions as y, or 2xN.") |
2973 |
| - # using list comps rather than arrays to preserve units |
2974 |
| - lower = [thisy - thiserr for (thisy, thiserr) |
2975 |
| - in cbook.safezip(y, yerr)] |
2976 |
| - upper = [thisy + thiserr for (thisy, thiserr) |
2977 |
| - in cbook.safezip(y, yerr)] |
2978 |
| - |
| 2976 | + lower, upper = extract_err(yerr, y) |
2979 | 2977 | # select points without upper/lower limits in y and
|
2980 | 2978 | # draw normal errorbars for these points
|
2981 | 2979 | noylims = ~(lolims | uplims)
|
|
0 commit comments