diff --git a/lib/matplotlib/rcsetup.py b/lib/matplotlib/rcsetup.py index 200518e80070..829646b8a784 100644 --- a/lib/matplotlib/rcsetup.py +++ b/lib/matplotlib/rcsetup.py @@ -367,12 +367,16 @@ def validate_color(s): return 'None' except AttributeError: pass + + if isinstance(s, six.string_types): + if len(s) == 6 or len(s) == 8: + stmp = '#' + s + if is_color_like(stmp): + return stmp + if is_color_like(s): return s - stmp = '#' + s - if is_color_like(stmp): - return stmp # If it is still valid, it must be a tuple. colorarg = s msg = '' diff --git a/lib/matplotlib/tests/test_colors.py b/lib/matplotlib/tests/test_colors.py index 072959eb8ff7..4f12766b7def 100644 --- a/lib/matplotlib/tests/test_colors.py +++ b/lib/matplotlib/tests/test_colors.py @@ -18,7 +18,7 @@ from numpy.testing.utils import assert_array_equal, assert_array_almost_equal from nose.plugins.skip import SkipTest -from cycler import cycler +from matplotlib import cycler import matplotlib import matplotlib.colors as mcolors import matplotlib.cm as cm @@ -615,6 +615,14 @@ def test_cn(): assert mcolors.to_hex("C0") == '#0343df' assert mcolors.to_hex("C1") == '#ff0000' + matplotlib.rcParams['axes.prop_cycle'] = cycler('color', ['8e4585', 'r']) + + assert mcolors.to_hex("C0") == '#8e4585' + # if '8e4585' gets parsed as a float before it gets detected as a hex + # colour it will be interpreted as a very large number. + # this mustn't happen. + assert mcolors.to_rgb("C0")[0] != np.inf + def test_conversions(): # to_rgba_array("none") returns a (0, 4) array.