Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4e1df0b

Browse filesBrowse files
efiringtacaswell
authored andcommitted
Merge pull request matplotlib#7639 from tacaswell/enh_color_names
Enh color names
1 parent 6e2e1dc commit 4e1df0b
Copy full SHA for 4e1df0b

File tree

Expand file treeCollapse file tree

5 files changed

+59
-8
lines changed
Filter options
Expand file treeCollapse file tree

5 files changed

+59
-8
lines changed

‎doc/users/colors.rst

Copy file name to clipboardExpand all lines: doc/users/colors.rst
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +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 ``{'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).
2024

2125
All string specifications of color are case-insensitive.
2226

‎doc/users/dflt_style_changes.rst

Copy file name to clipboardExpand all lines: doc/users/dflt_style_changes.rst
+7-2Lines 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

Copy file name to clipboardExpand all lines: lib/matplotlib/_color_data.py
+19-2Lines changed: 19 additions & 2 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,6 +15,24 @@
1515
'w': (1, 1, 1)}
1616

1717

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+
)
31+
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())
35+
1836
# This mapping of color names -> hex values is taken from
1937
# a survey run by Randel Monroe see:
2038
# http://blog.xkcd.com/2010/05/03/color-survey-results/
@@ -973,7 +991,6 @@
973991
'green': '#15b01a',
974992
'purple': '#7e1e9c'}
975993

976-
977994
# Normalize name to "xkcd:<name>" to avoid name collisions.
978995
XKCD_COLORS = {'xkcd:' + name: value for name, value in XKCD_COLORS.items()}
979996

‎lib/matplotlib/colors.py

Copy file name to clipboardExpand all lines: lib/matplotlib/colors.py
+10-3Lines changed: 10 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, CSS4_COLORS, XKCD_COLORS
69+
from ._color_data import BASE_COLORS, TABLEAU_COLORS, CSS4_COLORS, XKCD_COLORS
7070

7171

7272
class _ColorMapping(dict):
@@ -86,7 +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)
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})
9097
_colors_full_map.update(BASE_COLORS)
9198
_colors_full_map = _ColorMapping(_colors_full_map)
9299

@@ -253,7 +260,7 @@ def to_hex(c, keep_alpha=False):
253260
### Backwards-compatible color-conversion API
254261

255262
cnames = CSS4_COLORS
256-
COLOR_NAMES = {'xkcd': XKCD_COLORS, 'css4': CSS4_COLORS}
263+
COLOR_NAMES = {'xkcd': XKCD_COLORS, 'css4': CSS4_COLORS, 'tc': TABLEAU_COLORS}
257264
hexColorPattern = re.compile("\A#[a-fA-F0-9]{6}\Z")
258265

259266

@@ -404,7 +411,7 @@ class Colormap(object):
404411
405412
"""
406413
def __init__(self, name, N=256):
407-
r"""
414+
"""
408415
Parameters
409416
----------
410417
name : str

‎lib/matplotlib/tests/test_colors.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_colors.py
+19-1Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,9 +583,10 @@ def angled_plane(azimuth, elevation, angle, x, y):
583583
assert_array_almost_equal(h, np.cos(np.radians(angle)))
584584

585585

586-
def test_xkcd():
586+
def test_color_names():
587587
assert mcolors.to_hex("blue") == "#0000ff"
588588
assert mcolors.to_hex("xkcd:blue") == "#0343df"
589+
assert mcolors.to_hex("tab:blue") == "#1f77b4"
589590

590591

591592
def _sph2cart(theta, phi):
@@ -655,6 +656,23 @@ def test_conversions():
655656
hex_color)
656657

657658

659+
def test_grey_gray():
660+
color_mapping = mcolors._colors_full_map
661+
for k in color_mapping.keys():
662+
if 'grey' in k:
663+
assert color_mapping[k] == color_mapping[k.replace('grey', 'gray')]
664+
if 'gray' in k:
665+
assert color_mapping[k] == color_mapping[k.replace('gray', 'grey')]
666+
667+
668+
def test_tableau_order():
669+
dflt_cycle = ['#1f77b4', '#ff7f0e', '#2ca02c', '#d62728',
670+
'#9467bd', '#8c564b', '#e377c2', '#7f7f7f',
671+
'#bcbd22', '#17becf']
672+
673+
assert list(mcolors.TABLEAU_COLORS.values()) == dflt_cycle
674+
675+
658676
if __name__ == '__main__':
659677
import nose
660678
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.