{"record":{"id":"d93c528ab3270097","repo":"matplotlib/matplotlib","slug":"s-r-does-not-look-like-a-color-arg","errorCode":null,"errorMessage":"{s!r} does not look like a color arg","messagePattern":"(.+?) does not look like a color arg","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"lib/matplotlib/rcsetup.py","lineNumber":372,"sourceCode":"def _validate_color_or_linecolor(s):\n    if cbook._str_equal(s, 'linecolor'):\n        return s\n    elif cbook._str_equal(s, 'mfc') or cbook._str_equal(s, 'markerfacecolor'):\n        return 'markerfacecolor'\n    elif cbook._str_equal(s, 'mec') or cbook._str_equal(s, 'markeredgecolor'):\n        return 'markeredgecolor'\n    elif s is None:\n        return None\n    elif isinstance(s, str) and len(s) == 6 or len(s) == 8:\n        stmp = '#' + s\n        if is_color_like(stmp):\n            return stmp\n        if s.lower() == 'none':\n            return None\n    elif is_color_like(s):\n        return s\n\n    raise ValueError(f'{s!r} does not look like a color arg')\n\n\ndef validate_color(s):\n    \"\"\"Return a valid color arg.\"\"\"\n    if isinstance(s, str):\n        if s.lower() == 'none':\n            return 'none'\n        if len(s) == 6 or len(s) == 8:\n            stmp = '#' + s\n            if is_color_like(stmp):\n                return stmp\n\n    if is_color_like(s):\n        return s\n\n    # If it is still valid, it must be a tuple (as a string from matplotlibrc).\n    try:\n        color = ast.literal_eval(s)","sourceCodeStart":354,"sourceCodeEnd":390,"githubUrl":"https://github.com/matplotlib/matplotlib/blob/b379c1b69e012b142c0f496a52bcb30513802d72/lib/matplotlib/rcsetup.py#L354-L390","documentation":"Raised by _validate_color_or_linecolor(), the validator for the legend.labelcolor rcParam family. It accepts the special keyword 'linecolor' (match the line color) or anything validate_color accepts: named colors, 6/8-digit hex with or without the leading '#', 'none', and RGB(A) tuples. Anything else, including misspelled color names or keywords like 'edge', is rejected with 'does not look like a color arg'.","triggerScenarios":"Setting plt.rcParams['legend.labelcolor'] to a misspelled name ('grey' instead of 'gray'), a keyword from a different rcParam ('edge', which belongs to patch edgecolor), or a malformed hex string such as 'ff0' (3 digits).","commonSituations":"Using the British spelling 'grey' (matplotlib only ships 'gray'); copying the value of another rcParam like patch.edgecolor='edge' into legend.labelcolor; truncating hex colors in template-rendered config files.","solutions":["Use a name from matplotlib.colors.get_named_colors_mapping() ('gray', 'tab:red', 'C2' are all fine here)","Use full 6- or 8-digit hex ('#ff0000' or 'ff0000')","Use the intended keyword 'linecolor' if you wanted the legend text to match line colors"],"exampleFix":"# before\nplt.rcParams['legend.labelcolor'] = 'grey'  # not a named color\n\n# after\nplt.rcParams['legend.labelcolor'] = 'gray'","handlingStrategy":"validation","validationCode":"from matplotlib.colors import is_color_like\n\ndef valid_labelcolor(s):\n    return s == 'linecolor' or is_color_like(s)\n\nassert valid_labelcolor('linecolor')\nassert not valid_labelcolor('edge')","typeGuard":"from matplotlib.colors import is_color_like\n\ndef is_labelcolor(s) -> bool:\n    return isinstance(s, str) and (s == 'linecolor' or is_color_like(s))","tryCatchPattern":"try:\n    mpl.rcParams['legend.labelcolor'] = value\nexcept ValueError:\n    mpl.rcParams['legend.labelcolor'] = 'linecolor'  # safe default\n    warnings.warn(f'ignoring invalid legend.labelcolor {value!r}')","preventionTips":["Remember US spelling: 'gray' not 'grey'","'edge' belongs to other rcParams; legend.labelcolor's keyword is 'linecolor'","Validate theme dicts once at load time instead of at plot time"],"tags":["matplotlib","color","legend","rcparams"],"backgroundTag":"invalid-color-value","analyzedSha":"b379c1b69e012b142c0f496a52bcb30513802d72","analyzedAt":"2026-08-21T23:31:55.468Z","schemaVersion":2},"datasetVersion":"2026-08-22T04:17:13.399Z"}