11from __future__ import division , generators
22import math , sys , warnings , datetime , new
3+ from operator import itemgetter
4+ import itertools
35
46import numpy as np
57from numpy import ma
3133import matplotlib .ticker as mticker
3234import matplotlib .transforms as mtransforms
3335
34- from operator import itemgetter
3536
3637iterable = cbook .iterable
3738is_string_like = cbook .is_string_like
@@ -115,11 +116,18 @@ def set_default_color_cycle(clist):
115116 :class:`Axes` to which it will apply; it will
116117 apply to all future axes.
117118
118- *clist* is a sequence of mpl color specifiers
119+ *clist* is a sequence of mpl color specifiers.
120+
121+ See also: :meth:`~matplotlib.axes.Axes.set_color_cycle`.
122+
123+ .. Note:: Deprecated 2010/01/03.
124+ Set rcParams['axes.color_cycle'] directly.
119125
120126 """
121- _process_plot_var_args .defaultColors = clist [:]
122- rcParams ['lines.color' ] = clist [0 ]
127+ rcParams ['axes.color_cycle' ] = clist
128+ warnings .warn ("Set rcParams['axes.color_cycle'] directly" ,
129+ DeprecationWarning )
130+
123131
124132class _process_plot_var_args :
125133 """
@@ -134,42 +142,18 @@ class _process_plot_var_args:
134142
135143 an arbitrary number of *x*, *y*, *fmt* are allowed
136144 """
137-
138- defaultColors = ['b' ,'g' ,'r' ,'c' ,'m' ,'y' ,'k' ]
139145 def __init__ (self , axes , command = 'plot' ):
140146 self .axes = axes
141147 self .command = command
142- self ._clear_color_cycle ()
143-
144- def _clear_color_cycle (self ):
145- self .colors = _process_plot_var_args .defaultColors [:]
146- # if the default line color is a color format string, move it up
147- # in the que
148- try :
149- ind = self .colors .index (rcParams ['lines.color' ])
150- except ValueError :
151- self .firstColor = rcParams ['lines.color' ]
152- else :
153- self .colors [0 ], self .colors [ind ] = self .colors [ind ], self .colors [0 ]
154- self .firstColor = self .colors [0 ]
155-
156- self .Ncolors = len (self .colors )
148+ self .set_color_cycle ()
157149
158- self .count = 0
159-
160- def set_color_cycle (self , clist ):
161- self .colors = clist [:]
162- self .firstColor = self .colors [0 ]
163- self .Ncolors = len (self .colors )
164- self .count = 0
150+ def set_color_cycle (self , clist = None ):
151+ if clist is None :
152+ clist = rcParams ['axes.color_cycle' ]
153+ self ._colors = itertools .cycle (clist )
165154
166155 def _get_next_cycle_color (self ):
167- if self .count == 0 :
168- color = self .firstColor
169- else :
170- color = self .colors [int (self .count % self .Ncolors )]
171- self .count += 1
172- return color
156+ return self ._colors .next ()
173157
174158 def __call__ (self , * args , ** kwargs ):
175159
@@ -907,9 +891,10 @@ def set_color_cycle(self, clist):
907891 """
908892 Set the color cycle for any future plot commands on this Axes.
909893
910- clist is a list of mpl color specifiers.
894+ * clist* is a list of mpl color specifiers.
911895 """
912896 self ._get_lines .set_color_cycle (clist )
897+ self ._get_patches_for_fill .set_color_cycle (clist )
913898
914899
915900 def ishold (self ):
0 commit comments