22
22
import operator
23
23
import os
24
24
import warnings
25
+ import re
26
+
25
27
try :
26
28
import collections .abc as abc
27
29
except ImportError :
30
32
from matplotlib .fontconfig_pattern import parse_fontconfig_pattern
31
33
from matplotlib .colors import is_color_like
32
34
35
+
33
36
# Don't let the original cycler collide with our validating cycler
34
37
from cycler import Cycler , cycler as ccycler
35
38
36
- #interactive_bk = ['gtk', 'gtkagg', 'gtkcairo', 'qt4agg',
39
+ # interactive_bk = ['gtk', 'gtkagg', 'gtkcairo', 'qt4agg',
37
40
# 'tkagg', 'wx', 'wxagg', 'cocoaagg', 'webagg']
38
41
# The capitalized forms are needed for ipython at present; this may
39
42
# change for later versions.
@@ -175,6 +178,7 @@ def validate_string_or_None(s):
175
178
except ValueError :
176
179
raise ValueError ('Could not convert "%s" to string' % s )
177
180
181
+
178
182
def validate_axisbelow (s ):
179
183
try :
180
184
return validate_bool (s )
@@ -340,6 +344,22 @@ def validate_color_or_auto(s):
340
344
return validate_color (s )
341
345
342
346
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
+
343
363
def validate_color (s ):
344
364
'return a valid color arg'
345
365
try :
@@ -649,7 +669,7 @@ def validate_hatch(s):
649
669
characters: ``\\ / | - + * . x o O``.
650
670
651
671
"""
652
- if not isinstance (s , six .text_type ):
672
+ if not isinstance (s , six .string_types ):
653
673
raise ValueError ("Hatch pattern must be a string" )
654
674
unique_chars = set (s )
655
675
unknown = (unique_chars -
@@ -661,7 +681,8 @@ def validate_hatch(s):
661
681
662
682
663
683
_prop_validators = {
664
- 'color' : validate_colorlist ,
684
+ 'color' : _listify_validator (validate_color_for_prop_cycle ,
685
+ allow_stringlist = True ),
665
686
'linewidth' : validate_floatlist ,
666
687
'linestyle' : validate_stringlist ,
667
688
'facecolor' : validate_colorlist ,
@@ -818,6 +839,9 @@ def validate_cycler(s):
818
839
norm_prop = _prop_aliases .get (prop , prop )
819
840
cycler_inst .change_key (prop , norm_prop )
820
841
842
+ for key , vals in cycler_inst .by_key ().items ():
843
+ _prop_validators [key ](vals )
844
+
821
845
return cycler_inst
822
846
823
847
0 commit comments