8000 BUG/API : fix color validation · matplotlib/matplotlib@ff99a04 · GitHub
[go: up one dir, main page]

Skip to content

Commit ff99a04

Browse files
committed
BUG/API : fix color validation
Possible fix for #4192. This adds a new validation (validate_color_or_None) method for color which allows None and restores `validate_color` to fail on None. This will allow selected color rcparams to be `None` (not `'None'`) which the library should interpret as "don't use this rcparam".
1 parent e783caa commit ff99a04

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

lib/matplotlib/rcsetup.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -235,18 +235,31 @@ def __call__(self, s):
235235
raise ValueError('Could not convert all entries to ints')
236236

237237

238+
def validate_color_or_None(s):
239+
if s is None:
240+
return None
241+
return validate_color(s)
242+
243+
238244
def validate_color(s):
239245
'return a valid color arg'
240-
if s in (None, 'none', 'None'):
241-
return None
246+
if s is None:
247+
raise ValueError('%s does not look like a color arg' % (s, ))
242248

243249
if is_color_like(s):
244250
return s
245251

246252
stmp = '#' + s
253+
247254
if is_color_like(stmp):
248255
return stmp
249256

257+
try:
258+
if s.lower() == 'none':
259+
return 'None'
260+
except AttributeError:
261+
pass
262+
250263
# If it is still valid, it must be a tuple.
251264
colorarg = s
252265
msg = ''
@@ -685,9 +698,8 @@ def __call__(self, s):
685698
# the relative size of legend markers vs. original
686699
'legend.markerscale': [1.0, validate_float],
687700
'legend.shadow': [False, validate_bool],
688-
'legend.facecolor': [None, validate_color], # background color; white
689-
'legend.edgecolor': [None, validate_color], # edge color; black
690-
701+
'legend.facecolor': [None, validate_color_or_None],
702+
'legend.edgecolor': [None, validate_color_or_None],
691703

692704
## tick properties
693705
'xtick.major.size': [4, validate_float], # major xtick size in points

0 commit comments

Comments
 (0)
0