Skip to content

Allow tuples of 4 floats as color rcparams. #9038

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 22, 2017
Merged
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
4 changes: 2 additions & 2 deletions lib/matplotlib/rcsetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,8 @@ def validate_color(s):
# get rid of grouping symbols
stmp = ''.join([c for c in s if c.isdigit() or c == '.' or c == ','])
vals = stmp.split(',')
if len(vals) != 3:
msg = '\nColor tuples must be length 3'
if len(vals) not in [3, 4]:
msg = '\nColor tuples must be of length 3 or 4'
else:
try:
colorarg = [float(val) for val in vals]
Expand Down
22 changes: 22 additions & 0 deletions lib/matplotlib/tests/test_rcparams.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from matplotlib.rcsetup import (validate_bool_maybe_none,
validate_stringlist,
validate_colorlist,
validate_color,
validate_bool,
validate_nseq_int,
validate_nseq_float,
Expand Down Expand Up @@ -324,6 +325,27 @@ def generate_validator_testcases(valid):
'fail': (('fish', ValueError),
),
},
{'validator': validate_color,
'success': (('None', 'none'),
('none', 'none'),
('AABBCC', '#AABBCC'), # RGB hex code
('AABBCC00', '#AABBCC00'), # RGBA hex code
('tab:blue', 'tab:blue'), # named color
('C0', 'C0'), # color from cycle
('(0, 1, 0)', [0.0, 1.0, 0.0]), # RGB tuple
((0, 1, 0), (0, 1, 0)), # non-string version
('(0, 1, 0, 1)', [0.0, 1.0, 0.0, 1.0]), # RGBA tuple
((0, 1, 0, 1), (0, 1, 0, 1)), # non-string version
('(0, 1, "0.5")', [0.0, 1.0, 0.5]), # unusual but valid

),
'fail': (('tab:veryblue', ValueError), # invalid name
('C123', ValueError), # invalid RGB(A) code and cycle index
('(0, 1)', ValueError), # tuple with length < 3
('(0, 1, 0, 1, 0)', ValueError), # tuple with length > 4
('(0, 1, none)', ValueError), # cannot cast none to float
),
},
{'validator': validate_hist_bins,
'success': (('auto', 'auto'),
('10', 10),
Expand Down