8000 Adding names to the color in the new Vega10 color cycle · matplotlib/matplotlib@c480623 · GitHub
[go: up one dir, main page]

Skip to content

Commit c480623

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

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

doc/users/colors.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ 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 ``{'blue', 'orange', 'green', 'red', 'purple', 'brown', 'pink', 'gray', 'olive', 'cyan'}``
2021

2122
All string specifications of color are case-insensitive.
2223

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+
VEGA10_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 "vega:<name>" to avoid name collisions.
32+
VEGA10_COLORS = {'vega:' + name: value for name, value in VEGA10_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, VEGA10_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(VEGA10_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': VEGA10_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

0 commit comments

Comments
 (0)
0