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

Skip to content

Commit 44d7127

Browse files
trphamtacaswell
authored andcommitted
Adding names to the color in the new Vega10 color cycle
1 parent 37592eb commit 44d7127

File tree

4 files changed

+26
-4
lines changed

4 files changed

+26
-4
lines changed

doc/users/colors.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ 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'}``
2023

2124
All string specifications of color are case-insensitive.
2225

lib/matplotlib/_color_data.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +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()}
33+
34+
1835
# This mapping of color names -> hex values is taken from
1936
# a survey run by Randel Monroe see:
2037
# http://blog.xkcd.com/2010/05/03/color-survey-results/

lib/matplotlib/colors.py

Lines changed: 4 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, VEGA_COLORS, CSS4_COLORS, XKCD_COLORS
7070

7171

7272
class _ColorMapping(dict):
@@ -87,6 +87,7 @@ def __delitem__(self, key, value):
8787
# Set by reverse priority order.
8888
_colors_full_map.update(XKCD_COLORS)
8989
_colors_full_map.update(CSS4_COLORS)
90+
_colors_full_map.update(VEGA_COLORS)
9091
_colors_full_map.update(BASE_COLORS)
9192
_colors_full_map = _ColorMapping(_colors_full_map)
9293

@@ -253,7 +254,7 @@ def to_hex(c, keep_alpha=False):
253254
### Backwards-compatible color-conversion API
254255

255256
cnames = CSS4_COLORS
256-
COLOR_NAMES = {'xkcd': XKCD_COLORS, 'css4': CSS4_COLORS}
257+
COLOR_NAMES = {'xkcd': XKCD_COLORS, 'css4': CSS4_COLORS, 'vega': VEGA_COLORS}
257258
hexColorPattern = re.compile("\A#[a-fA-F0-9]{6}\Z")
258259

259260

@@ -404,7 +405,7 @@ class Colormap(object):
404405
405406
"""
406407
def __init__(self, name, N=256):
407-
r"""
408+
"""
408409
Parameters
409410
----------
410411
name : str

lib/matplotlib/tests/test_colors.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,9 +571,10 @@ def angled_plane(azimuth, elevation, angle, x, y):
571571
assert_array_almost_equal(h, np.cos(np.radians(angle)))
572572

573573

574-
def test_xkcd():
574+
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"
577578

578579

579580
def _sph2cart(theta, phi):

0 commit comments

Comments
 (0)