Closed
Description
Problem
It took me some year to figure out, that matplotlib supports 'CN'
(e.g. 'C1'
) as color.
I tried 1
(integer), but that raises only a ValueError: 1 is not a valid value for color
(triggered by plt.plot(np.arange(10), color=1)
)
and when I implemented a workaround to support integers in our wrappers, a colleague asked about the difference to 'CN'
.
Proposed solution
Current code:
matplotlib/lib/matplotlib/colors.py
Lines 240 to 246 in 62a5ba4
Suggestion:
Add some more text to the exception message, when the type is an integer, e.g.:
def _check_color_like(**kwargs):
"""
For each *key, value* pair in *kwargs*, check that *value* is color-like.
"""
for k, v in kwargs.items():
if not is_color_like(v):
if isinstance(v, int) and k == "color" and v >= 0:
raise ValueError(
f"{v!r} is not a valid value for {k}.\n"
f"To get the N'th entry from mpl.rcParams['axes.prop_cycle'] you can use 'CN' instead of an integer.")
raise ValueError(f"{v!r} is not a valid value for {k}")