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

Skip to content

Commit 7a034d2

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 bbf8684 commit 7a034d2

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
@@ -225,18 +225,31 @@ def __call__(self, s):
225225
raise ValueError('Could not convert all entries to ints')
226226

227227

228+
def validate_color_or_None(s):
229+
if s is None:
230+
return None
231+
return validate_color(s)
232+
233+
228234
def validate_color(s):
229235
'return a valid color arg'
230-
if s in (None, 'none', 'None'):
231-
return None
236+
if s is None:
237+
raise ValueError('%s does not look like a color arg' % (s, ))
232238

233239
if is_color_like(s):
234240
return s
235241

236242
stmp = '#' + s
243+
237244
if is_color_like(stmp):
238245
return stmp
239246

247+
try:
248+
if s.lower() == 'none':
249+
return 'None'
250+
except AttributeError:
251+
pass
252+
240253
# If it is still valid, it must be a tuple.
241254
colorarg = s
242255
msg = ''
@@ -661,9 +674,8 @@ def __call__(self, s):
661674
# the relative size of legend markers vs. original
662675
'legend.markerscale': [1.0, validate_float],
663676
'legend.shadow': [False, validate_bool],
664-
'legend.facecolor': [None, validate_color], # background color; white
665-
'legend.edgecolor': [None, validate_color], # edge color; black
666-
677+
'legend.facecolor': [None, validate_color_or_None],
678+
'legend.edgecolor': [None, validate_color_or_None],
667679

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

0 commit comments

Comments
 (0)
0