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

Skip to content

Commit 317eaff

Browse files
committed
API/DOC: change color name to tab from vega
- change naming to tab - credit Tableau for developing the colors - support both spellings of grey an Tableau&xkcd colors - add tests of grey/gray equivalence and tableau order - use more explicit internal names + add comment
1 parent 44d7127 commit 317eaff

File tree

5 files changed

+55
-26
lines changed

5 files changed

+55
-26
lines changed

doc/users/colors.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ it can be provided as:
1717
* a name from the `xkcd color survey <https://xkcd.com/color/rgb/>`__
1818
prefixed with ``'xkcd:'`` (e.g., ``'xkcd:sky blue'``)
1919
* one of ``{'C0', 'C1', 'C2', 'C3', 'C4', 'C5', 'C6', 'C7', 'C8', 'C9'}``
20-
* one of ``{'vega:blue', 'vega:orange', 'vega:green',
21-
'vega:red', 'vega:purple', 'vega:brown', 'vega:pink',
22-
'vega:gray', 'vega:olive', 'vega:cyan'}``
20+
* one of ``{'tab:blue', 'tab:orange', 'tab:green',
21+
'tab:red', 'tab:purple', 'tab:brown', 'tab:pink',
22+
'tab:gray', 'tab:olive', 'tab:cyan'}`` which are the Tableau Colors from the
23+
'T10' categorical palette (which is the default color cycle).
2324

2425
All string specifications of color are case-insensitive.
2526

doc/users/dflt_style_changes.rst

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,13 @@ Colors in default property cycle
3232
--------------------------------
3333

3434
The colors in the default property cycle have been changed from
35-
``['b', 'g', 'r', 'c', 'm', 'y', 'k']`` to the `Vega category10 palette
36-
<https://github.com/vega/vega/wiki/Scales#scale-range-literals>`__
35+
``['b', 'g', 'r', 'c', 'm', 'y', 'k']`` to the category10
36+
color palette used by `Vega
37+
<https://github.com/vega/vega/wiki/Scales#scale-range-literals>`__ and
38+
`d3
39+
<https://github.com/d3/d3-3.x-api-reference/blob/master/Ordinal-Scales.md#category10>`__
40+
originally developed at Tableau.
41+
3742

3843
.. plot::
3944

lib/matplotlib/_color_data.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import (absolute_import, division, print_function,
22
unicode_literals)
3-
3+
from collections import OrderedDict
44
import six
55

66

@@ -15,22 +15,23 @@
1515
'w': (1, 1, 1)}
1616

1717

18-
VEGA_COLORS = {
19-
'blue': '#1f77b4',
20-
'orange': '#ff7f0e',
21-
'green': '#2ca02c',
22-
'red': '#d62728',
23-
'purple': '#9467bd',
24-
'brown': '#8c564b',
25-
'pink': '#e377c2',
26-
'gray': '#7f7f7f',
27-
'olive': '#bcbd22',
28-
'cyan': '#17becf'}
29-
30-
31-
# Normalize name to "vega10:<name>" to avoid name collisions.
32-
VEGA_COLORS = {'vega:' + name: value for name, value in VEGA_COLORS.items()}
18+
# These colors are from Tableau
19+
TABLEAU_COLORS = OrderedDict((
20+
('blue', '#1f77b4'),
21+
('orange', '#ff7f0e'),
22+
('green', '#2ca02c'),
23+
('red', '#d62728'),
24+
('purple', '#9467bd'),
25+
('brown', '#8c564b'),
26+
('pink', '#e377c2'),
27+
('gray', '#7f7f7f'),
28+
('olive', '#bcbd22'),
29+
('cyan', '#17becf'))
30+
)
3331

32+
# Normalize name to "tab:<name>" to avoid name collisions.
33+
TABLEAU_COLORS = OrderedDict(
34+
('tab:' + name, value) for name, value in TABLEAU_COLORS.items())
3435

3536
# This mapping of color names -> hex values is taken from
3637
# a survey run by Randel Monroe see:
@@ -990,7 +991,6 @@
990991
'green': '#15b01a',
991992
'purple': '#7e1e9c'}
992993

993-
994994
# Normalize name to "xkcd:<name>" to avoid name collisions.
995995
XKCD_COLORS = {'xkcd:' + name: value for name, value in XKCD_COLORS.items()}
996996

lib/matplotlib/colors.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
import numpy as np
6767
from numpy import ma
6868
import matplotlib.cbook as cbook
69-
from ._color_data import BASE_COLORS, VEGA_COLORS, CSS4_COLORS, XKCD_COLORS
69+
from ._color_data import BASE_COLORS, TABLEAU_COLORS, CSS4_COLORS, XKCD_COLORS
7070

7171

7272
class _ColorMapping(dict):
@@ -86,8 +86,14 @@ def __delitem__(self, key, value):
8686
_colors_full_map = {}
8787
# Set by reverse priority order.
8888
_colors_full_map.update(XKCD_COLORS)
89+
_colors_full_map.update({k.replace('grey', 'gray'): v
90+
for k, v in XKCD_COLORS.items()
91+
if 'grey' in k})
8992
_colors_full_map.update(CSS4_COLORS)
90-
_colors_full_map.update(VEGA_COLORS)
93+
_colors_full_map.update(TABLEAU_COLORS)
94+
_colors_full_map.update({k.replace('gray', 'grey'): v
95+
for k, v in TABLEAU_COLORS.items()
96+
if 'gray' in k})
9197
_colors_full_map.update(BASE_COLORS)
9298
_colors_full_map = _ColorMapping(_colors_full_map)
9399

@@ -254,7 +260,7 @@ def to_hex(c, keep_alpha=False):
254260
### Backwards-compatible color-conversion API
255261

256262
cnames = CSS4_COLORS
257-
COLOR_NAMES = {'xkcd': XKCD_COLORS, 'css4': CSS4_COLORS, 'vega': VEGA_COLORS}
263+
COLOR_NAMES = {'xkcd': XKCD_COLORS, 'css4': CSS4_COLORS, 'tc': TABLEAU_COLORS}
258264
hexColorPattern = re.compile("\A#[a-fA-F0-9]{6}\Z")
259265

260266

lib/matplotlib/tests/test_colors.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ def angled_plane(azimuth, elevation, angle, x, y):
574574
def test_color_names():
575575
assert mcolors.to_hex("blue") == "#0000ff"
576576
assert mcolors.to_hex("xkcd:blue") == "#0343df"
577-
assert mcolors.to_hex("vega:blue") == "#1f77b4"
577+
assert mcolors.to_hex("tab:blue") == "#1f77b4"
578578

579579

580580
def _sph2cart(theta, phi):
@@ -644,6 +644,23 @@ def test_conversions():
644644
hex_color)
645645

646646

647+
def test_grey_gray():
648+
color_mapping = mcolors._colors_full_map
649+
for k in color_mapping.keys():
650+
if 'grey' in k:
651+
assert color_mapping[k] == color_mapping[k.replace('grey', 'gray')]
652+
if 'gray' in k:
653+
assert color_mapping[k] == color_mapping[k.replace('gray', 'grey')]
654+
655+
656+
def test_tableau_order():
657+
dflt_cycle = ['#1f77b4', '#ff7f0e', '#2ca02c', '#d62728',
658+
'#9467bd', '#8c564b', '#e377c2', '#7f7f7f',
659+
'#bcbd22', '#17becf']
660+
661+
assert list(mcolors.TABLEAU_COLORS.values()) == dflt_cycle
662+
663+
647664
if __name__ == '__main__':
648665
import nose
649666
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)

0 commit comments

Comments
 (0)