@@ -869,23 +869,26 @@ def _use_dynamic_x(self):
869
869
870
870
return (freq is not None ) and self ._is_dynamic_freq (freq )
871
871
872
+ def _get_colors (self ):
873
+ import matplotlib .pyplot as plt
874
+ cycle = '' .join (plt .rcParams .get ('axes.color_cycle' , list ('bgrcmyk' )))
875
+ has_colors = 'colors' in self .kwds
876
+ colors = self .kwds .pop ('colors' , cycle )
877
+ return has_colors , colors
878
+
872
879
def _make_plot (self ):
873
880
# this is slightly deceptive
874
881
if self .use_index and self ._use_dynamic_x ():
875
882
data = self ._maybe_convert_index (self .data )
876
883
self ._make_ts_plot (data , ** self .kwds )
877
884
else :
878
- import matplotlib .pyplot as plt
879
- cycle = '' .join (plt .rcParams .get ('axes.color_cycle' ,
880
- list ('bgrcmyk' )))
881
- has_colors = 'colors' in self .kwds
882
- colors = self .kwds .pop ('colors' , cycle )
883
885
lines = []
884
886
labels = []
885
887
x = self ._get_xticks (convert_period = True )
886
888
889
+ has_colors , colors = self ._get_colors ()
887
890
def _maybe_add_color (kwargs , style , i ):
888
- if (has_colors and
891
+ if (not has_colors and
889
892
(style is None or re .match ('[a-z]+' , style ) is None )):
890
893
kwargs ['color' ] = colors [i % len (colors )]
891
894
@@ -923,19 +926,15 @@ def _maybe_add_color(kwargs, style, i):
923
926
924
927
def _make_ts_plot (self , data , ** kwargs ):
925
928
from pandas .tseries .plotting import tsplot
926
- import matplotlib .pyplot as plt
927
929
kwargs = kwargs .copy ()
928
- cycle = '' .join (plt .rcParams .get ('axes.color_cycle' , list ('bgrcmyk' )))
929
-
930
- has_colors = 'colors' in kwargs
931
- colors = kwargs .pop ('colors' , '' .join (cycle ))
930
+ has_colors , colors = self ._get_colors ()
932
931
933
932
plotf = self ._get_plot_function ()
934
933
lines = []
935
934
labels = []
936
935
937
936
def _maybe_add_color (kwargs , style , i ):
938
- if (has_colors and
937
+ if (not has_colors and
939
938
(style is None or re .match ('[a-z]+' , style ) is None )):
940
939
kwargs ['color' ] = colors [i % len (colors )]
941
940
@@ -948,11 +947,11 @@ def to_leg_label(label, i):
948
947
ax = self ._get_ax (0 ) #self.axes[0]
949
948
style = self .style or ''
950
949
label = com ._stringify (self .label )
951
-
952
- _maybe_add_color (kwargs , style , 0 )
950
+ kwds = kwargs . copy ()
951
+ _maybe_add_color (kwds , style , 0 )
953
952
954
953
newlines = tsplot (data , plotf , ax = ax , label = label , style = self .style ,
955
- ** kwargs )
954
+ ** kwds )
956
955
ax .grid (self .grid )
957
956
lines .append (newlines [0 ])
958
957
leg_label = to_leg_label (label , 0 )
@@ -964,7 +963,7 @@ def to_leg_label(label, i):
964
963
style = self ._get_style (i , col )
965
964
kwds = kwargs .copy ()
966
965
967
- _maybe_add_color (kwargs , style , i )
966
+ _maybe_add_color (kwds , style , i )
968
967
969
968
newlines = tsplot (data [col ], plotf , ax = ax , label = label ,
970
969
style = style , ** kwds )
0 commit comments