@@ -2791,9 +2791,26 @@ def errorbar(self, x, y, yerr=None, xerr=None,
2791
2791
warnings .warn (msg , mplDeprecation , stacklevel = 1 )
2792
2792
2793
2793
plot_line = (fmt .lower () != 'none' )
2794
-
2795
2794
label = kwargs .pop ("label" , None )
2796
2795
2796
+ fmt_style_kwargs = {k : v for k , v in
2797
+ zip (('linestyle' , 'marker' , 'color' ),
2798
+ _process_plot_format (fmt )) if v is not None }
2799
+
2800
+ if ('color' in kwargs or 'color' in fmt_style_kwargs or
2801
+ ecolor is not None ):
2802
+ base_style = {}
2803
+ else :
2804
+ base_style = six .next (self ._get_lines .prop_cycler )
2805
+
2806
+ base_style ['label' ] = '_nolegend_'
2807
+ base_style ['color' ] = kwargs .pop ('color' )
2808
+ base_style .update (fmt_style_kwargs )
2809
+ if ecolor is not None :
2810
+ base_style ['color' ] = ecolor
2811
+ if 'color' not in base_style :
2812
+ base_style ['color' ] = 'b'
2813
+
2797
2814
# make sure all the args are iterable; use lists not arrays to
2798
2815
# preserve units
2799
2816
if not iterable (x ):
@@ -2815,12 +2832,15 @@ def errorbar(self, x, y, yerr=None, xerr=None,
2815
2832
# Instead of using zorder, the line plot is being added
2816
2833
# either here, or after all the errorbar plot elements.
2817
2834
if barsabove and plot_line :
2818
- l0 , = self .plot (x , y , fmt , label = "_nolegend_" , ** kwargs )
2835
+ # in python3.5+ this can be simplified
2836
+ eb_style = dict (base_style )
2837
+ eb_style .update (** kwargs )
2838
+ l0 , = self .plot (x , y , ** eb_style )
2819
2839
2820
2840
barcols = []
2821
2841
caplines = []
2822
2842
2823
- lines_kw = { 'label' : '_nolegend_' }
2843
+ lines_kw = dict ( base_style )
2824
2844
if elinewidth :
2825
2845
lines_kw ['linewidth' ] = elinewidth
2826
2846
else :
@@ -2832,25 +2852,16 @@ def errorbar(self, x, y, yerr=None, xerr=None,
2832
2852
lines_kw [key ] = kwargs [key ]
2833
2853
2834
2854
# arrays fine here, they are booleans and hence not units
2835
- if not iterable (lolims ):
2836
- lolims = np .asarray ([lolims ] * len (x ), bool )
2837
- else :
2838
- lolims = np .asarray (lolims , bool )
2839
-
2840
- if not iterable (uplims ):
2841
- uplims = np .array ([uplims ] * len (x ), bool )
2842
- else :
2843
- uplims = np .asarray (uplims , bool )
2855
+ def _bool_asarray_helper (d , expected ):
2856
+ if not iterable (d ):
2857
+ lolims = np .asarray ([d ] * expected , bool )
2858
+ else :
2859
+ lolims = np .asarray (lolims , bool )
2844
2860
2845
- if not iterable (xlolims ):
2846
- xlolims = np .array ([xlolims ] * len (x ), bool )
2847
- else :
2848
- xlolims = np .asarray (xlolims , bool )
2849
-
2850
- if not iterable (xuplims ):
2851
- xuplims = np .array ([xuplims ] * len (x ), bool )
2852
- else :
2853
- xuplims = np .asarray (xuplims , bool )
2861
+ lolims = _bool_asarray_helper (lolims , len (x ))
2862
+ uplims = _bool_asarray_helper (uplims , len (x ))
2863
+ xlolims = _bool_asarray_helper (xlolims , len (x ))
2864
+ xuplims = _bool_asarray_helper (xuplims , len (x ))
2854
2865
2855
2866
everymask = np .arange (len (x )) % errorevery == 0
2856
2867
@@ -2865,7 +2876,11 @@ def xywhere(xs, ys, mask):
2865
2876
ys = [thisy for thisy , b in zip (ys , mask ) if b ]
2866
2877
return xs , ys
2867
2878
2868
- plot_kw = {'label' : '_nolegend_' }
2879
+ plot_kw = dict (base_style )
2880
+ # eject any marker information from format string
2881
+ plot_kw .pop ('marker' , None )
2882
+ plot_kw .pop ('ls' , None )
2883
+ plot_kw .pop ('linestyle' , None )
2869
2884
if capsize is None :
2870
2885
capsize = rcParams ["errorbar.capsize" ]
2871
2886
if capsize > 0 :
@@ -2885,7 +2900,7 @@ def xywhere(xs, ys, mask):
2885
2900
2886
2901
if xerr is not None :
2887
2902
if (iterable (xerr ) and len (xerr ) == 2 and
2888
- iterable (xerr [0 ]) and iterable (xerr [1 ])):
2903
+ iterable (xerr [0 ]) and iterable (xerr [1 ])):
2889
2904
# using list comps rather than arrays to preserve units
2890
2905
left = [thisx - thiserr for (thisx , thiserr )
2891
2906
in cbook .safezip (x , xerr [0 ])]
@@ -2914,8 +2929,8 @@ def xywhere(xs, ys, mask):
2914
2929
lo , ro = xywhere (left , right , noxlims & everymask )
2915
2930
barcols .append (self .hlines (yo , lo , ro , ** lines_kw ))
2916
2931
if capsize > 0 :
2917
- caplines .extend (self .plot (lo , yo , 'k |' , ** plot_kw ))
2918
- caplines .extend (self .plot (ro , yo , 'k |' , ** plot_kw ))
2932
+ caplines .extend (self .plot (lo , yo , '|' , ** plot_kw ))
2933
+ caplines .extend (self .plot (ro , yo , '|' , ** plot_kw ))
2919
2934
2920
2935
if xlolims .any ():
2921
2936
yo , _ = xywhere (y , right , xlolims & everymask )
@@ -2931,7 +2946,7 @@ def xywhere(xs, ys, mask):
2931
2946
** plot_kw ))
2932
2947
if capsize > 0 :
2933
2948
xlo , ylo = xywhere (x , y , xlolims & everymask )
2934
- caplines .extend (self .plot (xlo , ylo , 'k |' , ** plot_kw ))
2949
+ caplines .extend (self .plot (xlo , ylo , '|' , ** plot_kw ))
2935
2950
2936
2951
if xuplims .any ():
2937
2952
yo , _ = xywhere (y , right , xuplims & everymask )
@@ -2947,7 +2962,7 @@ def xywhere(xs, ys, mask):
2947
2962
** plot_kw ))
2948
2963
if capsize > 0 :
2949
2964
xup , yup = xywhere (x , y , xuplims & everymask )
2950
- caplines .extend (self .plot (xup , yup , 'k |' , ** plot_kw ))
2965
+ caplines .extend (self .plot (xup , yup , '|' , ** plot_kw ))
2951
2966
2952
2967
if yerr is not None :
2953
2968
if (iterable (yerr ) and len (yerr ) == 2 and
@@ -2978,8 +2993,8 @@ def xywhere(xs, ys, mask):
2978
2993
lo , uo = xywhere (lower , upper , noylims & everymask )
2979
2994
barcols .append (self .vlines (xo , lo , uo , ** lines_kw ))
2980
2995
if capsize > 0 :
2981
- caplines .extend (self .plot (xo , lo , 'k_ ' , ** plot_kw ))
2982
- caplines .extend (self .plot (xo , uo , 'k_ ' , ** plot_kw ))
2996
+ caplines .extend (self .plot (xo , lo , '_ ' , ** plot_kw ))
2997
+ caplines .extend (self .plot (xo , uo , '_ ' , ** plot_kw ))
2983
2998
2984
2999
if lolims .any ():
2985
3000
xo , _ = xywhere (x , lower , lolims & everymask )
@@ -3016,12 +3031,6 @@ def xywhere(xs, ys, mask):
3016
3031
if not barsabove and plot_line :
3017
3032
l0 , = self .plot (x , y , fmt , label = '_nolegend_' , ** kwargs )
3018
3033
3019
- if ecolor is None :
3020
- if l0 is None and 'color' in self ._get_lines ._prop_keys :
3021
- ecolor = six .next (self ._get_lines .prop_cycler )['color' ]
3022
- else :
3023
- ecolor = l0 .get_color ()
3024
-
3025
3034
for l in barcols :
3026
3035
l .set_color (ecolor )
3027
3036
for l in caplines :
0 commit comments