MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / validate_color

Function validate_color

lib/matplotlib/rcsetup.py:375–397  ·  view source on GitHub ↗

Return a valid color arg.

(s)

Source from the content-addressed store, hash-verified

373
374
375def validate_color(s):
376 """Return a valid color arg."""
377 if isinstance(s, str):
378 if s.lower() == 'none':
379 return 'none'
380 if len(s) == 6 or len(s) == 8:
381 stmp = '#' + s
382 if is_color_like(stmp):
383 return stmp
384
385 if is_color_like(s):
386 return s
387
388 # If it is still valid, it must be a tuple (as a string from matplotlibrc).
389 try:
390 color = ast.literal_eval(s)
391 except (SyntaxError, ValueError):
392 pass
393 else:
394 if is_color_like(color):
395 return color
396
397 raise ValueError(f'{s!r} does not look like a color arg')
398
399
400def _validate_color_or_None(s):

Callers 5

validate_color_or_autoFunction · 0.85
_validate_color_or_edgeFunction · 0.85
_validate_color_or_NoneFunction · 0.85

Calls 1

is_color_likeFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…