Skip to content

Enh color names #7639

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions doc/users/colors.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ it can be provided as:
* a name from the `xkcd color survey <https://xkcd.com/color/rgb/>`__
prefixed with ``'xkcd:'`` (e.g., ``'xkcd:sky blue'``)
* one of ``{'C0', 'C1', 'C2', 'C3', 'C4', 'C5', 'C6', 'C7', 'C8', 'C9'}``
* one of ``{'tab:blue', 'tab:orange', 'tab:green',
'tab:red', 'tab:purple', 'tab:brown', 'tab:pink',
'tab:gray', 'tab:olive', 'tab:cyan'}`` which are the Tableau Colors from the
'T10' categorical palette (which is the default color cycle).

All string specifications of color are case-insensitive.

Expand Down
9 changes: 7 additions & 2 deletions doc/users/dflt_style_changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,13 @@ Colors in default property cycle
--------------------------------

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add link here to the Tableau blog post describing their development?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I offered to let Tableau pick where this link goes, still waiting to hear back from them.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will work on getting you that link soon.



.. plot::

Expand Down
21 changes: 19 additions & 2 deletions lib/matplotlib/_color_data.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import (absolute_import, division, print_function,
unicode_literals)

from collections import OrderedDict
import six


Expand All @@ -15,6 +15,24 @@
'w': (1, 1, 1)}


# These colors are from Tableau
TABLEAU_COLORS = OrderedDict((
('blue', '#1f77b4'),
('orange', '#ff7f0e'),
('green', '#2ca02c'),
('red', '#d62728'),
('purple', '#9467bd'),
('brown', '#8c564b'),
('pink', '#e377c2'),
('gray', '#7f7f7f'),
('olive', '#bcbd22'),
('cyan', '#17becf'))
)

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

# This mapping of color names -> hex values is taken from
# a survey run by Randel Monroe see:
# http://blog.xkcd.com/2010/05/03/color-survey-results/
Expand Down Expand Up @@ -973,7 +991,6 @@
'green': '#15b01a',
'purple': '#7e1e9c'}


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

Expand Down
13 changes: 10 additions & 3 deletions lib/matplotlib/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
import numpy as np
from numpy import ma
import matplotlib.cbook as cbook
from ._color_data import BASE_COLORS, CSS4_COLORS, XKCD_COLORS
from ._color_data import BASE_COLORS, TABLEAU_COLORS, CSS4_COLORS, XKCD_COLORS


class _ColorMapping(dict):
Expand All @@ -86,7 +86,14 @@ def __delitem__(self, key, value):
_colors_full_map = {}
# Set by reverse priority order.
_colors_full_map.update(XKCD_COLORS)
_colors_full_map.update({k.replace('grey', 'gray'): v
for k, v in XKCD_COLORS.items()
if 'grey' in k})
_colors_full_map.update(CSS4_COLORS)
_colors_full_map.update(TABLEAU_COLORS)
_colors_full_map.update({k.replace('gray', 'grey'): v
for k, v in TABLEAU_COLORS.items()
if 'gray' in k})
_colors_full_map.update(BASE_COLORS)
_colors_full_map = _ColorMapping(_colors_full_map)

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

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


Expand Down Expand Up @@ -404,7 +411,7 @@ class Colormap(object):

"""
def __init__(self, name, N=256):
r"""
"""
Parameters
----------
name : str
Expand Down
20 changes: 19 additions & 1 deletion lib/matplotlib/tests/test_colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -571,9 +571,10 @@ def angled_plane(azimuth, elevation, angle, x, y):
assert_array_almost_equal(h, np.cos(np.radians(angle)))


def test_xkcd():
def test_color_names():
assert mcolors.to_hex("blue") == "#0000ff"
assert mcolors.to_hex("xkcd:blue") == "#0343df"
assert mcolors.to_hex("tab:blue") == "#1f77b4"


def _sph2cart(theta, phi):
Expand Down Expand Up @@ -643,6 +644,23 @@ def test_conversions():
hex_color)


def test_grey_gray():
color_mapping = mcolors._colors_full_map
for k in color_mapping.keys():
if 'grey' in k:
assert color_mapping[k] == color_mapping[k.replace('grey', 'gray')]
if 'gray' in k:
assert color_mapping[k] == color_mapping[k.replace('gray', 'grey')]


def test_tableau_order():
dflt_cycle = ['#1f77b4', '#ff7f0e', '#2ca02c', '#d62728',
'#9467bd', '#8c564b', '#e377c2', '#7f7f7f',
'#bcbd22', '#17becf']

assert list(mcolors.TABLEAU_COLORS.values()) == dflt_cycle


if __name__ == '__main__':
import nose
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)