Skip to content
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

Colours like 'XeYYYY' don't get recognised properly if X, Y's are numbers #6701

Merged
merged 5 commits into from Jul 11, 2016
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a comment reminding future readers why this needs to happen first?

if isinstance(s, six.string_types):
if len(s) == 6 or len(s) == 8:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you do this with a regex?

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