Skip to content

Commit 080ed75

Browse files
committed
Base colors are not special.
1 parent 0386f9d commit 080ed75

File tree

3 files changed

+20
-15
lines changed

3 files changed

+20
-15
lines changed

examples/color/named_colors.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from matplotlib import colors as mcolors
1515

1616

17-
colors = mcolors.CSS4_COLORS
17+
colors = dict(mcolors.BASE_COLORS, **mcolors.CSS4_COLORS)
1818

1919
# Sort by hue, saturation, value and name.
2020
by_hsv = sorted((tuple(mcolors.rgb_to_hsv(mcolors.to_rgba(color)[:3])), name)

lib/matplotlib/_color_data.py

+12
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,18 @@
33

44
from matplotlib.externals import six
55

6+
7+
BASE_COLORS = {
8+
'b': (0, 0, 1),
9+
'g': (0, 0.5, 0),
10+
'r': (1, 0, 0),
11+
'c': (0, 0.75, 0.75),
12+
'm': (0.75, 0, 0.75),
13+
'y': (0.75, 0.75, 0),
14+
'k': (0, 0, 0),
15+
'w': (1, 1, 1)}
16+
17+
618
# This mapping of color names -> hex values is taken from
719
# a survey run by Randel Monroe see:
820
# http://blog.xkcd.com/2010/05/03/color-survey-results/

lib/matplotlib/colors.py

+7-14
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,13 @@
6565
import numpy as np
6666
from numpy import ma
6767
import matplotlib.cbook as cbook
68-
from ._color_data import XKCD_COLORS, CSS4_COLORS
68+
from ._color_data import BASE_COLORS, CSS4_COLORS, XKCD_COLORS
6969

7070

7171
class _ColorMapping(dict):
72-
def __init__(self, mapping, cache):
72+
def __init__(self, mapping):
7373
super(_ColorMapping, self).__init__(mapping)
74-
self._cache = cache
74+
self._cache = {}
7575

7676
def __setitem__(self, key, value):
7777
super(_ColorMapping, self).__setitem__(key, value)
@@ -82,18 +82,11 @@ def __delitem__(self, key, value):
8282
self._cache.clear()
8383

8484

85-
_colors_full_map = {
86-
'b': (0, 0, 1),
87-
'g': (0, 0.5, 0),
88-
'r': (1, 0, 0),
89-
'c': (0, 0.75, 0.75),
90-
'm': (0.75, 0, 0.75),
91-
'y': (0.75, 0.75, 0),
92-
'k': (0, 0, 0),
93-
'w': (1, 1, 1)}
94-
_colors_full_map.update(XKCD_COLORS)
85+
_colors_full_map = {}
86+
_colors_full_map.update(BASE_COLORS)
9587
_colors_full_map.update(CSS4_COLORS)
96-
_colors_full_map = _ColorMapping(_colors_full_map, {})
88+
_colors_full_map.update(XKCD_COLORS)
89+
_colors_full_map = _ColorMapping(_colors_full_map)
9790

9891

9992
def get_named_colors_mapping():

0 commit comments

Comments
 (0)