Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3f72974

Browse files
committed
Merge pull request #6701 from myyc/master
FIX: hex parsing in rc files Colours like 'XeYYYY' don't get recognised properly if X, Y's are digits
1 parent 86f4a4e commit 3f72974

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

lib/matplotlib/rcsetup.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -367,12 +367,16 @@ def validate_color(s):
367367
return 'None'
368368
except AttributeError:
369369
pass
370+
371+
if isinstance(s, six.string_types):
372+
if len(s) == 6 or len(s) == 8:
373+
stmp = '#' + s
374+
if is_color_like(stmp):
375+
return stmp
376+
370377
if is_color_like(s):
371378
return s
372-
stmp = '#' + s
373379

374-
if is_color_like(stmp):
375-
return stmp
376380
# If it is still valid, it must be a tuple.
377381
colorarg = s
378382
msg = ''

lib/matplotlib/tests/test_colors.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from numpy.testing.utils import assert_array_equal, assert_array_almost_equal
1818
from nose.plugins.skip import SkipTest
1919

20-
from cycler import cycler
20+
from matplotlib import cycler
2121
import matplotlib
2222
import matplotlib.colors as mcolors
2323
import matplotlib.cm as cm
@@ -602,6 +602,14 @@ def test_cn():
602602
assert mcolors.to_hex("C0") == '#0343df'
603603
assert mcolors.to_hex("C1") == '#ff0000'
604604

605+
matplotlib.rcParams['axes.prop_cycle'] = cycler('color', ['8e4585', 'r'])
606+
607+
assert mcolors.to_hex("C0") == '#8e4585'
608+
# if '8e4585' gets parsed as a float before it gets detected as a hex
609+
# colour it will be interpreted as a very large number.
610+
# this mustn't happen.
611+
assert mcolors.to_rgb("C0")[0] != np.inf
612+
605613

606614
def test_conversions():
607615
# to_rgba_array("none") returns a (0, 4) array.

0 commit comments

Comments
 (0)