Skip to content

Commit

Permalink
Merge pull request #6701 from myyc/master
Browse files Browse the repository at this point in the history
FIX: hex parsing in rc files

Colours like 'XeYYYY' don't get recognised properly if X, Y's are digits
  • Loading branch information
tacaswell committed Jul 11, 2016
2 parents 92dbbad + 40e5a0a commit bc72786
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
10 changes: 7 additions & 3 deletions lib/matplotlib/rcsetup.py
Expand Up @@ -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 = ''
Expand Down
10 changes: 9 additions & 1 deletion lib/matplotlib/tests/test_colors.py
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit bc72786

Please sign in to comment.