diff --git a/lib/matplotlib/rcsetup.py b/lib/matplotlib/rcsetup.py index 0eafec792b04..7265b084d524 100644 --- a/lib/matplotlib/rcsetup.py +++ b/lib/matplotlib/rcsetup.py @@ -312,10 +312,11 @@ def validate_color(s): if isinstance(s, str): if s.lower() == 'none': return 'none' - if len(s) == 6 or len(s) == 8: - stmp = '#' + s - if is_color_like(stmp): - return stmp + # Support "rrggbb"/"rrggbbaa" without leading '#' as these would be + # interpreted as comments in matplotlibrc. Note that "rgb" -> "#rgb" + # is explicitly not supported, because of the ambiguity e.g. in "C10". + if len(s) in [6, 8] and {*s.lower()} <= {*"0123456789abcdef"}: + return f'#{s}' if is_color_like(s): return s diff --git a/tutorials/colors/colors.py b/tutorials/colors/colors.py index d5bcdc9b45b5..eb432c02d34d 100644 --- a/tutorials/colors/colors.py +++ b/tutorials/colors/colors.py @@ -14,6 +14,12 @@ +--------------------------------------+--------------------------------------+ | Case-insensitive hex RGB or RGBA | - ``'#0f0f0f'`` | | string. | - ``'#0f0f0f80'`` | +| | | +| .. note:: | | +| In a matplotlibrc file, and only | | +| there, these strings must be | | +| given without the leading '#', | | +| e.g. as ``text.color: 0f0f0f``. | | +--------------------------------------+--------------------------------------+ | Case-insensitive RGB or RGBA string | - ``'#abc'`` as ``'#aabbcc'`` | | equivalent hex shorthand of | - ``'#fb1'`` as ``'#ffbb11'`` |