Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions lib/matplotlib/rcsetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions tutorials/colors/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'`` |
Expand Down