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