{"record":{"id":"02b3eee623b3a19d","repo":"matplotlib/matplotlib","slug":"cannot-put-cycle-reference-s-r-in-prop-cycler","errorCode":null,"errorMessage":"Cannot put cycle reference ({s!r}) in prop_cycler","messagePattern":"Cannot put cycle reference \\((.+?)\\) in prop_cycler","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"lib/matplotlib/rcsetup.py","lineNumber":350,"sourceCode":"    return validate_color(s)\n\n\ndef validate_color_or_auto(s):\n    if cbook._str_equal(s, 'auto'):\n        return s\n    return validate_color(s)\n\n\ndef _validate_color_or_edge(s):\n    if cbook._str_equal(s, 'edge'):\n        return s\n    return validate_color(s)\n\n\ndef validate_color_for_prop_cycle(s):\n    # N-th color cycle syntax can't go into the color cycle.\n    if isinstance(s, str) and re.match(\"^C[0-9]$\", s):\n        raise ValueError(f\"Cannot put cycle reference ({s!r}) in prop_cycler\")\n    return validate_color(s)\n\n\ndef _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","sourceCodeStart":332,"sourceCodeEnd":368,"githubUrl":"https://github.com/matplotlib/matplotlib/blob/b379c1b69e012b142c0f496a52bcb30513802d72/lib/matplotlib/rcsetup.py#L332-L368","documentation":"Colors placed into the color cycle (axes.prop_cycle / the 'color' key of a cycler) must be concrete colors. Strings matching C0..C9 are cycle references that point at the cycle itself, which would be circular, so validate_color_for_prop_cycle() rejects them before the cycle is built. Any other valid color spec (named color, hex, tuple) is accepted.","triggerScenarios":"Calling plt.rc('axes', prop_cycle=cycler(color=['C0', 'C1'])) or putting 'color: c0, c1' inside a style/matplotlibrc file; building a cycler from a list of artist color kwargs that legitimately used C references elsewhere.","commonSituations":"Copying a per-line color like plt.plot(..., color='C1') into a custom color-cycle definition for a style file or a reusable plotting helper; converting old-style 'axes.color_cycle' rcParams content that contained C references.","solutions":["Replace each C reference with the actual palette entry it refers to, e.g. 'C0' -> 'tab:blue', 'C1' -> 'tab:orange' (the default tab10 cycle)","Or pass explicit hex/named colors: cycler(color=['#1f77b4', '#ff7f0e'])","Keep C0..C9 only for per-artist color= kwargs, never inside prop_cycle"],"exampleFix":"# before\nfrom cycler import cycler\nimport matplotlib.pyplot as plt\nplt.rc('axes', prop_cycle=cycler(color=['C0', 'C1']))  # ValueError\n\n# after\nplt.rc('axes', prop_cycle=cycler(color=['tab:blue', 'tab:orange']))","handlingStrategy":"validation","validationCode":"import re\nfrom matplotlib.colors import is_color_like\n\ndef valid_cycle_color(s):\n    return not (isinstance(s, str) and re.fullmatch(r'C[0-9]', s)) and is_color_like(s)\n\nassert not valid_cycle_color('C1')\nassert valid_cycle_color('tab:orange')","typeGuard":"import re\nfrom matplotlib.colors import is_color_like\n\ndef is_prop_cycle_color(s) -> bool:\n    return is_color_like(s) and not (isinstance(s, str) and re.fullmatch(r'C[0-9]', s))","tryCatchPattern":"from cycler import cycler\ntry:\n    plt.rc('axes', prop_cycle=cycler(color=color_list))\nexcept ValueError as e:\n    color_list = [c for c in color_list if not re.fullmatch(r'C[0-9]', str(c))]\n    plt.rc('axes', prop_cycle=cycler(color=color_list or ['tab:blue']))","preventionTips":["Reserve C0..C9 for per-artist color= kwargs only","When templating style files, lint 'color:' lines for bare cN tokens","Default custom cycles to explicit palette names (tab10 entries) so they survive this rule"],"tags":["matplotlib","color","prop-cycle","rcparams"],"backgroundTag":"invalid-color-value","analyzedSha":"b379c1b69e012b142c0f496a52bcb30513802d72","analyzedAt":"2026-08-21T23:31:55.468Z","schemaVersion":2},"datasetVersion":"2026-08-22T04:17:13.399Z"}