22from contextlib import ExitStack
33import functools
44import inspect
5- import itertools
65import logging
76from numbers import Real
87from operator import attrgetter
@@ -224,18 +223,11 @@ def __init__(self, command='plot'):
224223 self .command = command
225224 self .set_prop_cycle (None )
226225
227- def __getstate__ (self ):
228- # note: it is not possible to pickle a generator (and thus a cycler).
229- return {'command' : self .command }
230-
231- def __setstate__ (self , state ):
232- self .__dict__ = state .copy ()
233- self .set_prop_cycle (None )
234-
235226 def set_prop_cycle (self , cycler ):
236227 if cycler is None :
237228 cycler = mpl .rcParams ['axes.prop_cycle' ]
238- self .prop_cycler = itertools .cycle (cycler )
229+ self ._idx = 0
230+ self ._cycler_items = [* cycler ]
239231 self ._prop_keys = cycler .keys # This should make a copy
240232
241233 def __call__ (self , axes , * args , data = None , ** kwargs ):
@@ -315,7 +307,9 @@ def get_next_color(self):
315307 """Return the next color in the cycle."""
316308 if 'color' not in self ._prop_keys :
317309 return 'k'
318- return next (self .prop_cycler )['color' ]
310+ c = self ._cycler_items [self ._idx ]['color' ]
311+ self ._idx = (self ._idx + 1 ) % len (self ._cycler_items )
312+ return c
319313
320314 def _getdefaults (self , ignore , kw ):
321315 """
@@ -328,7 +322,8 @@ def _getdefaults(self, ignore, kw):
328322 if any (kw .get (k , None ) is None for k in prop_keys ):
329323 # Need to copy this dictionary or else the next time around
330324 # in the cycle, the dictionary could be missing entries.
331- default_dict = next (self .prop_cycler ).copy ()
325+ default_dict = self ._cycler_items [self ._idx ].copy ()
326+ self ._idx = (self ._idx + 1 ) % len (self ._cycler_items )
332327 for p in ignore :
333328 default_dict .pop (p , None )
334329 else :
0 commit comments