Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d90439a

Browse files
committed
Clarify handling of #rrggbb(aa) colors in matplotlibrc.
The inconsistency is not that great, but let's at least document it.
1 parent 581bf5d commit d90439a

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

lib/matplotlib/rcsetup.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -312,10 +312,12 @@ def validate_color(s):
312312
if isinstance(s, str):
313313
if s.lower() == 'none':
314314
return 'none'
315-
if len(s) == 6 or len(s) == 8:
316-
stmp = '#' + s
317-
if is_color_like(stmp):
318-
return stmp
315+
# Support "rrggbb"/"rggbbaa" without leading '#' because these would be
316+
# interpreted as comments in matplotlibrc. Note that this explicitly
317+
# does not support "rgb" to mean "#rgb", because of the ambiguity e.g.
318+
# in "C10".
319+
if len(s) in [6, 8] and {*s.lower()} <= {*"0123456789abcdef"}:
320+
return f'#{s}'
319321

320322
if is_color_like(s):
321323
return s

tutorials/colors/colors.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@
1414
+--------------------------------------+--------------------------------------+
1515
| Case-insensitive hex RGB or RGBA | - ``'#0f0f0f'`` |
1616
| string. | - ``'#0f0f0f80'`` |
17+
| | |
18+
| .. note:: | |
19+
| In a matplotlibrc file, and only | |
20+
| there, these strings must be | |
21+
| given without the leading '#', | |
22+
| e.g. as ``text.color: 0f0f0f``. | |
1723
+--------------------------------------+--------------------------------------+
1824
| Case-insensitive RGB or RGBA string | - ``'#abc'`` as ``'#aabbcc'`` |
1925
| equivalent hex shorthand of | - ``'#fb1'`` as ``'#ffbb11'`` |

0 commit comments

Comments
 (0)