From 84c9faf2eab172f77d3babc21abe4b258912e0af Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Tue, 15 Aug 2017 04:35:27 -0700 Subject: [PATCH 1/3] Allow tuples of 4 floats as color rcparams. --- lib/matplotlib/rcsetup.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/rcsetup.py b/lib/matplotlib/rcsetup.py index ae60b108f541..9c02211007ee 100644 --- a/lib/matplotlib/rcsetup.py +++ b/lib/matplotlib/rcsetup.py @@ -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] From 12da300198f90795920d6e5a6180d7cf77616059 Mon Sep 17 00:00:00 2001 From: "Adrien F. VINCENT" Date: Sat, 19 Aug 2017 12:44:43 -0700 Subject: [PATCH 2/3] Add a proper test for validate_color --- lib/matplotlib/tests/test_rcparams.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/lib/matplotlib/tests/test_rcparams.py b/lib/matplotlib/tests/test_rcparams.py index e84a90ee34cf..4ecf6bab1647 100644 --- a/lib/matplotlib/tests/test_rcparams.py +++ b/lib/matplotlib/tests/test_rcparams.py @@ -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, @@ -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), From 1f0378e27cdf451ce82d8f9a3965f31145096cbc Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Sun, 20 Aug 2017 15:31:54 -0400 Subject: [PATCH 3/3] STY: strip whitespace --- lib/matplotlib/tests/test_rcparams.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/tests/test_rcparams.py b/lib/matplotlib/tests/test_rcparams.py index 4ecf6bab1647..06650de2b37b 100644 --- a/lib/matplotlib/tests/test_rcparams.py +++ b/lib/matplotlib/tests/test_rcparams.py @@ -337,7 +337,7 @@ def generate_validator_testcases(valid): ('(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