@@ -228,7 +228,6 @@ def set_prop_cycle(self, cycler):
228
228
cycler = mpl .rcParams ['axes.prop_cycle' ]
229
229
self ._idx = 0
230
230
self ._cycler_items = [* cycler ]
231
- self ._prop_keys = cycler .keys # This should make a copy
232
231
233
232
def __call__ (self , axes , * args , data = None , ** kwargs ):
234
233
axes ._process_unit_info (kwargs = kwargs )
@@ -305,30 +304,27 @@ def __call__(self, axes, *args, data=None, **kwargs):
305
304
306
305
def get_next_color (self ):
307
306
"""Return the next color in the cycle."""
308
- if 'color' not in self ._prop_keys :
309
- return 'k'
310
- c = self ._cycler_items [self ._idx ]['color' ]
311
- self ._idx = (self ._idx + 1 ) % len (self ._cycler_items )
312
- return c
307
+ entry = self ._cycler_items [self ._idx ]
308
+ if "color" in entry :
309
+ self ._idx = (self ._idx + 1 ) % len (self ._cycler_items ) # Advance cycler.
310
+ return entry ["color" ]
311
+ else :
312
+ return "k"
313
313
314
- def _getdefaults (self , ignore , kw ):
314
+ def _getdefaults (self , kw , ignore = frozenset () ):
315
315
"""
316
316
If some keys in the property cycle (excluding those in the set
317
317
*ignore*) are absent or set to None in the dict *kw*, return a copy
318
318
of the next entry in the property cycle, excluding keys in *ignore*.
319
319
Otherwise, don't advance the property cycle, and return an empty dict.
320
320
"""
321
- prop_keys = self ._prop_keys - ignore
322
- if any (kw .get (k , None ) is None for k in prop_keys ):
323
- # Need to copy this dictionary or else the next time around
324
- # in the cycle, the dictionary could be missing entries.
325
- default_dict = self ._cycler_items [self ._idx ].copy ()
326
- self ._idx = (self ._idx + 1 ) % len (self ._cycler_items )
327
- for p in ignore :
328
- default_dict .pop (p , None )
321
+ defaults = self ._cycler_items [self ._idx ]
322
+ if any (kw .get (k , None ) is None for k in {* defaults } - ignore ):
323
+ self ._idx = (self ._idx + 1 ) % len (self ._cycler_items ) # Advance cycler.
324
+ # Return a new dict to avoid exposing _cycler_items entries to mutation.
325
+ return {k : v for k , v in defaults .items () if k not in ignore }
329
326
else :
330
- default_dict = {}
331
- return default_dict
327
+ return {}
332
328
333
329
def _setdefaults (self , defaults , kw ):
334
330
"""
@@ -341,8 +337,7 @@ def _setdefaults(self, defaults, kw):
341
337
342
338
def _makeline (self , axes , x , y , kw , kwargs ):
343
339
kw = {** kw , ** kwargs } # Don't modify the original kw.
344
- default_dict = self ._getdefaults (set (), kw )
345
- self ._setdefaults (default_dict , kw )
340
+ self ._setdefaults (self ._getdefaults (kw ), kw )
346
341
seg = mlines .Line2D (x , y , ** kw )
347
342
return seg , kw
348
343
@@ -362,18 +357,16 @@ def _makefill(self, axes, x, y, kw, kwargs):
362
357
# *user* explicitly specifies a marker which should be an error.
363
358
# We also want to prevent advancing the cycler if there are no
364
359
# defaults needed after ignoring the given properties.
365
- ignores = {'marker' , 'markersize' , 'markeredgecolor' ,
366
- 'markerfacecolor' , 'markeredgewidth' }
367
- # Also ignore anything provided by *kwargs*.
368
- for k , v in kwargs .items ():
369
- if v is not None :
370
- ignores .add (k )
360
+ ignores = ({'marker' , 'markersize' , 'markeredgecolor' ,
361
+ 'markerfacecolor' , 'markeredgewidth' }
362
+ # Also ignore anything provided by *kwargs*.
363
+ | {k for k , v in kwargs .items () if v is not None })
371
364
372
365
# Only using the first dictionary to use as basis
373
366
# for getting defaults for back-compat reasons.
374
367
# Doing it with both seems to mess things up in
375
368
# various places (probably due to logic bugs elsewhere).
376
- default_dict = self ._getdefaults (ignores , kw )
369
+ default_dict = self ._getdefaults (kw , ignores )
377
370
self ._setdefaults (default_dict , kw )
378
371
379
372
# Looks like we don't want "color" to be interpreted to
0 commit comments