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

Skip to content

Commit 9feeb9e

Browse files
committed
FIX: restore single character colors to rgb tuples
The hex representations are not exact which resulted in very small slight color changes.
1 parent b2543f6 commit 9feeb9e

File tree

1 file changed

+23
-21
lines changed

1 file changed

+23
-21
lines changed

lib/matplotlib/colors.py

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -105,17 +105,17 @@ class ColorConverter(object):
105105
*colorConverter*, is needed.
106106
"""
107107
colors = {
108-
'b': '#0000ff',
109-
'r': '#ff0000',
110-
'g': '#008000',
111-
'c': '#00bfbf',
112-
'm': '#bf00bf',
113-
'y': '#bfbf00',
114-
'k': '#000000',
115-
'w': '#ffffff'}
108+
'b': (0, 0, 1),
109+
'g': (0, 0.5, 0),
110+
'r': (1, 0, 0),
111+
'c': (0, 0.75, 0.75),
112+
'm': (0.75, 0, 0.75),
113+
'y': (0.75, 0.75, 0),
114+
'k': (0, 0, 0),
115+
'w': (1, 1, 1)}
116116

117117
cache = {}
118-
CN_LOOKUPS = [colors, ] + [COLOR_NAMES[k] for k in ['css4', 'xkcd']]
118+
CN_LOOKUPS = [COLOR_NAMES[k] for k in ['css4', 'xkcd']]
119119

120120
def to_rgb(self, arg):
121121
"""
@@ -152,18 +152,20 @@ def to_rgb(self, arg):
152152
try:
153153
if cbook.is_string_like(arg):
154154
argl = arg.lower()
155-
for cmapping in self.CN_LOOKUPS:
156-
str1 = cmapping.get(argl, argl)
157-
if str1 != argl:
158-
break
159-
if str1.startswith('#'):
160-
color = hex2color(str1)
161-
else:
162-
fl = float(argl)
163-
if fl < 0 or fl > 1:
164-
raise ValueError(
165-
'gray (string) must be in range 0-1')
166-
color = (fl,)*3
155+
color = self.colors.get(argl, None)
156+
if color is None:
157+
for cmapping in self.CN_LOOKUPS:
158+
str1 = cmapping.get(argl, argl)
159+
if str1 != argl:
160+
break
161+
if str1.startswith('#'):
162+
color = hex2color(str1)
163+
else:
164+
fl = float(argl)
165+
if fl < 0 or fl > 1:
166+
raise ValueError(
167+
'gray (string) must be in range 0-1')
168+
color = (fl,)*3
167169
elif cbook.iterable(arg):
168170
if len(arg) > 4 or len(arg) < 3:
169171
raise ValueError(

0 commit comments

Comments
 (0)