2222import operator
2323import os
2424import warnings
25+ import re
26+
2527try :
2628 import collections .abc as abc
2729except ImportError :
3032from matplotlib .fontconfig_pattern import parse_fontconfig_pattern
3133from matplotlib .colors import is_color_like
3234
35+
3336# Don't let the original cycler collide with our validating cycler
3437from cycler import Cycler , cycler as ccycler
3538
36- #interactive_bk = ['gtk', 'gtkagg', 'gtkcairo', 'qt4agg',
39+ # interactive_bk = ['gtk', 'gtkagg', 'gtkcairo', 'qt4agg',
3740# 'tkagg', 'wx', 'wxagg', 'cocoaagg', 'webagg']
3841# The capitalized forms are needed for ipython at present; this may
3942# change for later versions.
@@ -175,6 +178,7 @@ def validate_string_or_None(s):
175178 except ValueError :
176179 raise ValueError ('Could not convert "%s" to string' % s )
177180
181+
178182def validate_axisbelow (s ):
179183 try :
180184 return validate_bool (s )
@@ -340,6 +344,22 @@ def validate_color_or_auto(s):
340344 return validate_color (s )
341345
342346
347+ def validate_color_for_prop_cycle (s ):
348+ # Special-case the N-th color cycle syntax, this obviously can not
349+ # go in the color cycle.
350+ if isinstance (s , bytes ):
351+ match = re .match (b'^C[0-9]$' , s )
352+ if match is not None :
353+ raise ValueError ('Can not put cycle reference ({cn!r}) in '
354+ 'prop_cycler' .format (cn = s ))
355+ elif isinstance (s , six .text_type ):
356+ match = re .match ('^C[0-9]$' , s )
357+ if match is not None :
358+ raise ValueError ('Can not put cycle reference ({cn!r}) in '
359+ 'prop_cycler' .format (cn = s ))
360+ return validate_color (s )
361+
362+
343363def validate_color (s ):
344364 'return a valid color arg'
345365 try :
@@ -649,7 +669,7 @@ def validate_hatch(s):
649669 characters: ``\\ / | - + * . x o O``.
650670
651671 """
652- if not isinstance (s , six .text_type ):
672+ if not isinstance (s , six .string_types ):
653673 raise ValueError ("Hatch pattern must be a string" )
654674 unique_chars = set (s )
655675 unknown = (unique_chars -
@@ -661,7 +681,8 @@ def validate_hatch(s):
661681
662682
663683_prop_validators = {
664- 'color' : validate_colorlist ,
684+ 'color' : _listify_validator (validate_color_for_prop_cycle ,
685+ allow_stringlist = True ),
665686 'linewidth' : validate_floatlist ,
666687 'linestyle' : validate_stringlist ,
667688 'facecolor' : validate_colorlist ,
@@ -818,6 +839,9 @@ def validate_cycler(s):
818839 norm_prop = _prop_aliases .get (prop , prop )
819840 cycler_inst .change_key (prop , norm_prop )
820841
842+ for key , vals in cycler_inst .by_key ().items ():
843+ _prop_validators [key ](vals )
844+
821845 return cycler_inst
822846
823847
0 commit comments