diff --git a/doc/users/colors.rst b/doc/users/colors.rst index 18a5756f0ab5..94fe23ad0cbd 100644 --- a/doc/users/colors.rst +++ b/doc/users/colors.rst @@ -17,6 +17,9 @@ it can be provided as: * a name from the `xkcd color survey `__ prefixed with ``'xkcd:'`` (e.g., ``'xkcd:sky blue'``) * one of ``{'C0', 'C1', 'C2', 'C3', 'C4', 'C5', 'C6', 'C7', 'C8', 'C9'}`` +* one of ``{'vega:blue', 'vega:orange', 'vega:green', + 'vega:red', 'vega:purple', 'vega:brown', 'vega:pink', + 'vega:gray', 'vega:olive', 'vega:cyan'}`` All string specifications of color are case-insensitive. diff --git a/lib/matplotlib/_color_data.py b/lib/matplotlib/_color_data.py index 11a538f34722..d6244e1863f5 100644 --- a/lib/matplotlib/_color_data.py +++ b/lib/matplotlib/_color_data.py @@ -15,6 +15,23 @@ 'w': (1, 1, 1)} +VEGA_COLORS = { + 'blue': '#1f77b4', + 'orange': '#ff7f0e', + 'green': '#2ca02c', + 'red': '#d62728', + 'purple': '#9467bd', + 'brown': '#8c564b', + 'pink': '#e377c2', + 'gray': '#7f7f7f', + 'olive': '#bcbd22', + 'cyan': '#17becf'} + + +# Normalize name to "vega10:" to avoid name collisions. +VEGA_COLORS = {'vega:' + name: value for name, value in VEGA_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/ diff --git a/lib/matplotlib/colors.py b/lib/matplotlib/colors.py index 8a7e99faa988..eb8133f3d03d 100644 --- a/lib/matplotlib/colors.py +++ b/lib/matplotlib/colors.py @@ -65,7 +65,7 @@ import numpy as np import matplotlib.cbook as cbook -from ._color_data import BASE_COLORS, CSS4_COLORS, XKCD_COLORS +from ._color_data import BASE_COLORS, VEGA_COLORS, CSS4_COLORS, XKCD_COLORS class _ColorMapping(dict): @@ -86,6 +86,7 @@ def __delitem__(self, key, value): # Set by reverse priority order. _colors_full_map.update(XKCD_COLORS) _colors_full_map.update(CSS4_COLORS) +_colors_full_map.update(VEGA_COLORS) _colors_full_map.update(BASE_COLORS) _colors_full_map = _ColorMapping(_colors_full_map) @@ -250,7 +251,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, 'vega': VEGA_COLORS} hexColorPattern = re.compile("\A#[a-fA-F0-9]{6}\Z") @@ -401,7 +402,7 @@ class Colormap(object): """ def __init__(self, name, N=256): - r""" + """ Parameters ---------- name : str diff --git a/lib/matplotlib/tests/test_colors.py b/lib/matplotlib/tests/test_colors.py index ebfc41aa53e3..eac575c79013 100644 --- a/lib/matplotlib/tests/test_colors.py +++ b/lib/matplotlib/tests/test_colors.py @@ -572,9 +572,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("vega:blue") == "#1f77b4" def _sph2cart(theta, phi):