@@ -2602,7 +2602,9 @@ def errorbar(self, x, y, yerr=None, xerr=None,
2602
2602
These arguments can be used to indicate that a value gives
2603
2603
only upper/lower limits. In that case a caret symbol is
2604
2604
used to indicate this. lims-arguments may be of the same
2605
- type as *xerr* and *yerr*.
2605
+ type as *xerr* and *yerr*. To use limits with inverted
2606
+ axes, :meth:`set_xlim` or :meth:`set_ylim` must be called
2607
+ before :meth:`errorbar`.
2606
2608
2607
2609
*errorevery*: positive integer
2608
2610
subsamples the errorbars. e.g., if everyerror=5, errorbars for
@@ -2682,16 +2684,12 @@ def errorbar(self, x, y, yerr=None, xerr=None,
2682
2684
if elinewidth :
2683
2685
lines_kw ['linewidth' ] = elinewidth
2684
2686
else :
2685
- if 'linewidth' in kwargs :
2686
- lines_kw ['linewidth' ] = kwargs ['linewidth' ]
2687
- if 'lw' in kwargs :
2688
- lines_kw ['lw' ] = kwargs ['lw' ]
2689
- if 'transform' in kwargs :
2690
- lines_kw ['transform' ] = kwargs ['transform' ]
2691
- if 'alpha' in kwargs :
2692
- lines_kw ['alpha' ] = kwargs ['alpha' ]
2693
- if 'zorder' in kwargs :
2694
- lines_kw ['zorder' ] = kwargs ['zorder' ]
2687
+ for key in ('linewidth' , 'lw' ):
2688
+ if key in kwargs :
2689
+ lines_kw [key ] = kwargs [key ]
2690
+ for key in ('transform' , 'alpha' , 'zorder' ):
2691
+ if key in kwargs :
2692
+ lines_kw [key ] = kwargs [key ]
2695
2693
2696
2694
# arrays fine here, they are booleans and hence not units
2697
2695
if not iterable (lolims ):
@@ -2727,29 +2725,21 @@ def xywhere(xs, ys, mask):
2727
2725
ys = [thisy for thisy , b in zip (ys , mask ) if b ]
2728
2726
return xs , ys
2729
2727
2728
+ plot_kw = {'label' : '_nolegend_' }
2730
2729
if capsize > 0 :
2731
- plot_kw = {
2732
- 'ms' : 2 * capsize ,
2733
- 'label' : '_nolegend_' }
2734
- if capthick is not None :
2735
- # 'mew' has higher priority, I believe,
2736
- # if both 'mew' and 'markeredgewidth' exists.
2737
- # So, save capthick to markeredgewidth so that
2738
- # explicitly setting mew or markeredgewidth will
2739
- # over-write capthick.
2740
- plot_kw ['markeredgewidth' ] = capthick
2741
- # For backwards-compat, allow explicit setting of
2742
- # 'mew' or 'markeredgewidth' to over-ride capthick.
2743
- if 'markeredgewidth' in kwargs :
2744
- plot_kw ['markeredgewidth' ] = kwargs ['markeredgewidth' ]
2745
- if 'mew' in kwargs :
2746
- plot_kw ['mew' ] = kwargs ['mew' ]
2747
- if 'transform' in kwargs :
2748
- plot_kw ['transform' ] = kwargs ['transform' ]
2749
- if 'alpha' in kwargs :
2750
- plot_kw ['alpha' ] = kwargs ['alpha' ]
2751
- if 'zorder' in kwargs :
2752
- plot_kw ['zorder' ] = kwargs ['zorder' ]
2730
+ plot_kw ['ms' ] = 2. * capsize
2731
+ if capthick is not None :
2732
+ # 'mew' has higher priority, I believe,
2733
+ # if both 'mew' and 'markeredgewidth' exists.
2734
+ # So, save capthick to markeredgewidth so that
2735
+ # explicitly setting mew or markeredgewidth will
2736
+ # over-write capthick.
2737
+ plot_kw ['markeredgewidth' ] = capthick
2738
+ # For backwards-compat, allow explicit setting of
2739
+ # 'mew' or 'markeredgewidth' to over-ride capthick.
2740
+ for key in ('markeredgewidth' , 'mew' , 'transform' , 'alpha' , 'zorder' ):
2741
+ if key in kwargs :
2742
+ plot_kw [key ] = kwargs [key ]
2753
2743
2754
2744
if xerr is not None :
2755
2745
if (iterable (xerr ) and len (xerr ) == 2 and
@@ -2766,38 +2756,48 @@ def xywhere(xs, ys, mask):
2766
2756
right = [thisx + thiserr for (thisx , thiserr )
2767
2757
in cbook .safezip (x , xerr )]
2768
2758
2769
- yo , _ = xywhere (y , right , everymask )
2770
- lo , ro = xywhere (left , right , everymask )
2771
- barcols .append (self .hlines (yo , lo , ro , ** lines_kw ))
2772
- if capsize > 0 :
2773
- if xlolims .any ():
2774
- # can't use numpy logical indexing since left and
2775
- # y are lists
2776
- leftlo , ylo = xywhere (left , y , xlolims & everymask )
2777
-
2778
- caplines .extend (
2779
- self .plot (leftlo , ylo , ls = 'None' ,
2780
- marker = mlines .CARETLEFT , ** plot_kw ))
2781
- xlolims = ~ xlolims
2782
- leftlo , ylo = xywhere (left , y , xlolims & everymask )
2783
- caplines .extend (self .plot (leftlo , ylo , 'k|' , ** plot_kw ))
2759
+ # select points without upper/lower limits in x and
2760
+ # draw normal errorbars for these points
2761
+ noxlims = ~ (xlolims | xuplims )
2762
+ if noxlims .any ():
2763
+ yo , _ = xywhere (y , right , noxlims & everymask )
2764
+ lo , ro = xywhere (left , right , noxlims & everymask )
2765
+ barcols .append (self .hlines (yo , lo , ro , ** lines_kw ))
2766
+ if capsize > 0 :
2767
+ caplines .extend (self .plot (lo , yo , 'k|' , ** plot_kw ))
2768
+ caplines .extend (self .plot (ro , yo , 'k|' , ** plot_kw ))
2769
+
2770
+ if xlolims .any ():
2771
+ yo , _ = xywhere (y , right , xlolims & everymask )
2772
+ lo , ro = xywhere (x , right , xlolims & everymask )
2773
+ barcols .append (self .hlines (yo , lo , ro , ** lines_kw ))
2774
+ rightup , yup = xywhere (right , y , xlolims & everymask )
2775
+ if self .xaxis_inverted ():
2776
+ marker = mlines .CARETLEFT
2784
2777
else :
2785
-
2786
- leftlo , ylo = xywhere (left , y , everymask )
2787
- caplines .extend (self .plot (leftlo , ylo , 'k|' , ** plot_kw ))
2788
-
2789
- if xuplims .any ():
2790
-
2791
- rightup , yup = xywhere (right , y , xuplims & everymask )
2792
- caplines .extend (
2793
- self .plot (rightup , yup , ls = 'None' ,
2794
- marker = mlines .CARETRIGHT , ** plot_kw ))
2795
- xuplims = ~ xuplims
2796
- rightup , yup = xywhere (right , y , xuplims & everymask )
2797
- caplines .extend (self .plot (rightup , yup , 'k|' , ** plot_kw ))
2778
+ marker = mlines .CARETRIGHT
2779
+ caplines .extend (
2780
+ self .plot (rightup , yup , ls = 'None' , marker = marker ,
2781
+ ** plot_kw ))
2782
+ if capsize > 0 :
2783
+ xlo , ylo = xywhere (x , y , xlolims & everymask )
2784
+ caplines .extend (self .plot (xlo , ylo , 'k|' , ** plot_kw ))
2785
+
2786
+ if xuplims .any ():
2787
+ yo , _ = xywhere (y , right , xuplims & everymask )
2788
+ lo , ro = xywhere (left , x , xuplims & everymask )
2789
+ barcols .append (self .hlines (yo , lo , ro , ** lines_kw ))
2790
+ leftlo , ylo = xywhere (left , y , xuplims & everymask )
2791
+ if self .xaxis_inverted ():
2792
+ marker = mlines .CARETRIGHT
2798
2793
else :
2799
- rightup , yup = xywhere (right , y , everymask )
2800
- caplines .extend (self .plot (rightup , yup , 'k|' , ** plot_kw ))
2794
+ marker = mlines .CARETLEFT
2795
+ caplines .extend (
2796
+ self .plot (leftlo , ylo , ls = 'None' , marker = marker ,
2797
+ ** plot_kw ))
2798
+ if capsize > 0 :
2799
+ xup , yup = xywhere (x , y , xuplims & everymask )
2800
+ caplines .extend (self .plot (xup , yup , 'k|' , ** plot_kw ))
2801
2801
2802
2802
if yerr is not None :
2803
2803
if (iterable (yerr ) and len (yerr ) == 2 and
@@ -2814,35 +2814,48 @@ def xywhere(xs, ys, mask):
2814
2814
upper = [thisy + thiserr for (thisy , thiserr )
2815
2815
in cbook .safezip (y , yerr )]
2816
2816
2817
- xo , _ = xywhere (x , lower , everymask )
2818
- lo , uo = xywhere (lower , upper , everymask )
2819
- barcols .append (self .vlines (xo , lo , uo , ** lines_kw ))
2820
- if capsize > 0 :
2821
-
2822
- if lolims .any ():
2823
- xlo , lowerlo = xywhere (x , lower , lolims & everymask )
2824
- caplines .extend (
2825
- self .plot (xlo , lowerlo , ls = 'None' ,
2826
- marker = mlines .CARETDOWN , ** plot_kw ))
2827
- lolims = ~ lolims
2828
- xlo , lowerlo = xywhere (x , lower , lolims & everymask )
2829
- caplines .extend (self .plot (xlo , lowerlo , 'k_' , ** plot_kw ))
2817
+ # select points without upper/lower limits in y and
2818
+ # draw normal errorbars for these points
2819
+ noylims = ~ (lolims | uplims )
2820
+ if noylims .any ():
2821
+ xo , _ = xywhere (x , lower , noylims & everymask )
2822
+ lo , uo = xywhere (lower , upper , noylims & everymask )
2823
+ barcols .append (self .vlines (xo , lo , uo , ** lines_kw ))
2824
+ if capsize > 0 :
2825
+ caplines .extend (self .plot (xo , lo , 'k_' , ** plot_kw ))
2826
+ caplines .extend (self .plot (xo , uo , 'k_' , ** plot_kw ))
2827
+
2828
+ if lolims .any ():
2829
+ xo , _ = xywhere (x , lower , lolims & everymask )
2830
+ lo , uo = xywhere (y , upper , lolims & everymask )
2831
+ barcols .append (self .vlines (xo , lo , uo , ** lines_kw ))
2832
+ xup , upperup = xywhere (x , upper , lolims & everymask )
2833
+ if self .yaxis_inverted ():
2834
+ marker = mlines .CARETDOWN
2830
2835
else :
2831
- xlo , lowerlo = xywhere (x , lower , everymask )
2832
- caplines .extend (self .plot (xlo , lowerlo , 'k_' , ** plot_kw ))
2833
-
2834
- if uplims .any ():
2835
- xup , upperup = xywhere (x , upper , uplims & everymask )
2836
-
2837
- caplines .extend (
2838
- self .plot (xup , upperup , ls = 'None' ,
2839
- marker = mlines .CARETUP , ** plot_kw ))
2840
- uplims = ~ uplims
2841
- xup , upperup = xywhere (x , upper , uplims & everymask )
2842
- caplines .extend (self .plot (xup , upperup , 'k_' , ** plot_kw ))
2836
+ marker = mlines .CARETUP
2837
+ caplines .extend (
2838
+ self .plot (xup , upperup , ls = 'None' , marker = marker ,
2839
+ ** plot_kw ))
2840
+ if capsize > 0 :
2841
+ xlo , ylo = xywhere (x , y , lolims & everymask )
2842
+ caplines .extend (self .plot (xlo , ylo , 'k_' , ** plot_kw ))
2843
+
2844
+ if uplims .any ():
2845
+ xo , _ = xywhere (x , lower , uplims & everymask )
2846
+ lo , uo = xywhere (lower , y , uplims & everymask )
2847
+ barcols .append (self .vlines (xo , lo , uo , ** lines_kw ))
2848
+ xlo , lowerlo = xywhere (x , lower , uplims & everymask )
2849
+ if self .yaxis_inverted ():
2850
+ marker = mlines .CARETUP
2843
2851
else :
2844
- xup , upperup = xywhere (x , upper , everymask )
2845
- caplines .extend (self .plot (xup , upperup , 'k_' , ** plot_kw ))
2852
+ marker = mlines .CARETDOWN
2853
+ caplines .extend (
2854
+ self .plot (xlo , lowerlo , ls = 'None' , marker = marker ,
2855
+ ** plot_kw ))
2856
+ if capsize > 0 :
2857
+ xup , yup = xywhere (x , y , uplims & everymask )
2858
+ caplines .extend (self .plot (xup , yup , 'k_' , ** plot_kw ))
2846
2859
2847
2860
if not barsabove and fmt is not None :
2848
2861
l0 , = self .plot (x , y , fmt , ** kwargs )
0 commit comments