@@ -134,11 +134,14 @@ def _mpl_ge_1_5_0():
134
134
except ImportError :
135
135
return False
136
136
137
- if _mpl_ge_1_5_0 ():
137
+ try :
138
+ _CYCLER_INSTALLED = True
138
139
# Compat with mp 1.5, which uses cycler.
139
140
import cycler
140
141
colors = mpl_stylesheet .pop ('axes.color_cycle' )
141
142
mpl_stylesheet ['axes.prop_cycle' ] = cycler .cycler ('color' , colors )
143
+ except ImportError :
144
+ _CYCLER_INSTALLED = False
142
145
143
146
144
147
def _get_standard_kind (kind ):
@@ -884,7 +887,6 @@ def __init__(self, data, kind=None, by=None, subplots=False, sharex=None,
884
887
self .by = by
885
888
886
889
self .kind = kind
887
-
888
890
self .sort_columns = sort_columns
889
891
890
892
self .subplots = subplots
@@ -959,7 +961,9 @@ def __init__(self, data, kind=None, by=None, subplots=False, sharex=None,
959
961
960
962
self .table = table
961
963
962
- self .kwds = kwds
964
+ # init and validatecycler keyword
965
+ # ToDo: _validate_color_arg may change kwds to list
966
+ self .kwds = self ._init_cyclic_option (kwds )
963
967
964
968
self ._validate_color_args ()
965
969
@@ -993,6 +997,60 @@ def _validate_color_args(self):
993
997
" use one or the other or pass 'style' "
994
998
"without a color symbol" )
995
999
1000
+ def _init_cyclic_option (self , kwds ):
1001
+ """
1002
+ Convert passed kwds to cycler instance
1003
+ """
1004
+ if not _CYCLER_INSTALLED :
1005
+ return kwds
1006
+
1007
+ option = {}
1008
+ for key , value in compat .iteritems (kwds ):
1009
+ if isinstance (value , cycler .Cycler ):
1010
+ cycler_keys = value .keys
1011
+ if len (cycler_keys ) > 1 :
1012
+ msg = ("cycler should only contain "
1013
+ "passed keyword '{0}': {1}" )
1014
+ raise ValueError (msg .format (key , value ))
1015
+ if key not in cycler_keys :
1016
+ msg = ("cycler must contain "
1017
+ "passed keyword '{0}': {1}" )
1018
+ raise ValueError (msg .format (key , value ))
1019
+
1020
+ elif isinstance (value , list ):
1021
+ # instanciate cycler
1022
+ # to do: check mpl kwds which should handle list as it is
1023
+ cycler_value = cycler .cycler (key , value )
1024
+ value = cycler_value
1025
+
1026
+ option [key ] = value
1027
+ return option
1028
+
1029
+ def _get_cyclic_option (self , kwds , num ):
1030
+ """
1031
+ Get num-th element of cycler contained in passed kwds.
1032
+ """
1033
+ if not _CYCLER_INSTALLED :
1034
+ return kwds
1035
+
1036
+ option = {}
1037
+ for key , value in compat .iteritems (kwds ):
1038
+ if isinstance (value , cycler .Cycler ):
1039
+ # cycler() will implicitly loop, cycler will not
1040
+ # cycler 0.10 or later is required
1041
+ for i , v in enumerate (value ()):
1042
+ if i == num :
1043
+ try :
1044
+ option [key ] = v [key ]
1045
+ except KeyError :
1046
+ msg = ("cycler doesn't contain required "
1047
+ "key '{0}': {1}" )
1048
+ raise ValueError (msg .format (key , value ))
1049
+ break
1050
+ else :
1051
+ option [key ] = value
1052
+ return option
1053
+
996
1054
def _iter_data (self , data = None , keep_index = False , fillna = None ):
997
1055
if data is None :
998
1056
data = self .data
@@ -1013,6 +1071,9 @@ def _iter_data(self, data=None, keep_index=False, fillna=None):
1013
1071
1014
1072
@property
1015
1073
def nseries (self ):
1074
+ """
1075
+ Number of columns to be plotted. If data is a Series, return 1.
1076
+ """
1016
1077
if self .data .ndim == 1 :
1017
1078
return 1
1018
1079
else :
@@ -1161,6 +1222,7 @@ def _post_plot_logic_common(self, ax, data):
1161
1222
self ._apply_axis_properties (ax .xaxis , rot = self .rot ,
1162
1223
fontsize = self .fontsize )
1163
1224
self ._apply_axis_properties (ax .yaxis , fontsize = self .fontsize )
1225
+
1164
1226
elif self .orientation == 'horizontal' :
1165
1227
if self ._need_to_set_index :
1166
1228
yticklabels = [labels .get (y , '' ) for y in ax .get_yticks ()]
@@ -1696,8 +1758,10 @@ def _make_plot(self):
1696
1758
colors = self ._get_colors ()
1697
1759
for i , (label , y ) in enumerate (it ):
1698
1760
ax = self ._get_ax (i )
1761
+
1699
1762
kwds = self .kwds .copy ()
1700
1763
style , kwds = self ._apply_style_colors (colors , kwds , i , label )
1764
+ kwds = self ._get_cyclic_option (kwds , i )
1701
1765
1702
1766
errors = self ._get_errorbars (label = label , index = i )
1703
1767
kwds = dict (kwds , ** errors )
@@ -1829,13 +1893,20 @@ def __init__(self, data, **kwargs):
1829
1893
if self .logy or self .loglog :
1830
1894
raise ValueError ("Log-y scales are not supported in area plot" )
1831
1895
1896
+ # kwds should not be passed to line
1897
+ _fill_only_kwds = ['hatch' ]
1898
+
1832
1899
@classmethod
1833
1900
def _plot (cls , ax , x , y , style = None , column_num = None ,
1834
1901
stacking_id = None , is_errorbar = False , ** kwds ):
1835
1902
if column_num == 0 :
1836
1903
cls ._initialize_stacker (ax , stacking_id , len (y ))
1837
1904
y_values = cls ._get_stacked_values (ax , stacking_id , y , kwds ['label' ])
1838
- lines = MPLPlot ._plot (ax , x , y_values , style = style , ** kwds )
1905
+
1906
+ line_kwds = kwds .copy ()
1907
+ for attr in cls ._fill_only_kwds :
1908
+ line_kwds .pop (attr , None )
1909
+ lines = MPLPlot ._plot (ax , x , y_values , style = style , ** line_kwds )
1839
1910
1840
1911
# get data from the line to get coordinates for fill_between
1841
1912
xdata , y_values = lines [0 ].get_data (orig = False )
@@ -1939,6 +2010,8 @@ def _make_plot(self):
1939
2010
kwds = self .kwds .copy ()
1940
2011
kwds ['color' ] = colors [i % ncolors ]
1941
2012
2013
+ kwds = self ._get_cyclic_option (kwds , i )
2014
+
1942
2015
errors = self ._get_errorbars (label = label , index = i )
1943
2016
kwds = dict (kwds , ** errors )
1944
2017
@@ -2064,6 +2137,7 @@ def _make_plot(self):
2064
2137
ax = self ._get_ax (i )
2065
2138
2066
2139
kwds = self .kwds .copy ()
2140
+ kwds = self ._get_cyclic_option (kwds , i )
2067
2141
2068
2142
label = pprint_thing (label )
2069
2143
kwds ['label' ] = label
@@ -2180,6 +2254,7 @@ def _make_plot(self):
2180
2254
ax .set_ylabel (label )
2181
2255
2182
2256
kwds = self .kwds .copy ()
2257
+ kwds = self ._get_cyclic_option (kwds , i )
2183
2258
2184
2259
def blank_labeler (label , value ):
2185
2260
if value == 0 :
@@ -2320,6 +2395,7 @@ def _make_plot(self):
2320
2395
for i , (label , y ) in enumerate (self ._iter_data ()):
2321
2396
ax = self ._get_ax (i )
2322
2397
kwds = self .kwds .copy ()
2398
+ kwds = self ._get_cyclic_option (kwds , i )
2323
2399
2324
2400
ret , bp = self ._plot (ax , y , column_num = i ,
2325
2401
return_type = self .return_type , ** kwds )
@@ -2332,6 +2408,7 @@ def _make_plot(self):
2332
2408
y = self .data .values .T
2333
2409
ax = self ._get_ax (0 )
2334
2410
kwds = self .kwds .copy ()
2411
+ kwds = self ._get_cyclic_option (kwds , 0 )
2335
2412
2336
2413
ret , bp = self ._plot (ax , y , column_num = 0 ,
2337
2414
return_type = self .return_type , ** kwds )
0 commit comments