From f819a4407dc9181c57dc6c36158fe40e17ff717f Mon Sep 17 00:00:00 2001 From: Truong Pham Date: Mon, 24 Oct 2016 22:42:06 -0700 Subject: [PATCH 1/8] Adding names to the color in the new Vega10 color cycle --- doc/users/colors.rst | 1 + lib/matplotlib/_color_data.py | 17 +++++++++++++++++ lib/matplotlib/colors.py | 7 ++++--- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/doc/users/colors.rst b/doc/users/colors.rst index 18a5756f0ab5..56c2343c585a 100644 --- a/doc/users/colors.rst +++ b/doc/users/colors.rst @@ -17,6 +17,7 @@ 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 ``{'blue', 'orange', 'green', 'red', 'purple', 'brown', 'pink', 'gray', 'olive', '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..09b0693d89ef 100644 --- a/lib/matplotlib/_color_data.py +++ b/lib/matplotlib/_color_data.py @@ -15,6 +15,23 @@ 'w': (1, 1, 1)} +VEGA10_COLORS = { + 'blue': '#1f77b4', + 'orange': '#ff7f0e', + 'green': '#2ca02c', + 'red': '#d62728', + 'purple': '#9467bd', + 'brown': '#8c564b', + 'pink': '#e377c2', + 'gray': '#7f7f7f', + 'olive': '#bcbd22', + 'cyan': '#17becf'} + + +# Normalize name to "vega:" to avoid name collisions. +VEGA10_COLORS = {'vega:' + name: value for name, value in VEGA10_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..a6ce47f9c2c3 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, VEGA10_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(VEGA10_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': VEGA10_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 From 9d6247f75c3f9648a185e1dfd4ef58983869b669 Mon Sep 17 00:00:00 2001 From: Truong Pham Date: Wed, 26 Oct 2016 11:15:41 -0700 Subject: [PATCH 2/8] Add prefix vega10:__ to vega10 colors descriptions in colors.rst, fix pep8 style for VEGA10_COLORS dictionary in _color_data.py --- doc/users/colors.rst | 2 +- lib/matplotlib/_color_data.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/doc/users/colors.rst b/doc/users/colors.rst index 56c2343c585a..1fccb698b972 100644 --- a/doc/users/colors.rst +++ b/doc/users/colors.rst @@ -17,7 +17,7 @@ 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 ``{'blue', 'orange', 'green', 'red', 'purple', 'brown', 'pink', 'gray', 'olive', 'cyan'}`` +* one of ``{'vega10:blue', 'vega10:orange', 'vega10:green', 'vega10:red', 'vega10:purple', 'vega10:brown', 'vega10:pink', 'vega10:gray', 'vega10:olive', 'vega10:cyan'}`` All string specifications of color are case-insensitive. diff --git a/lib/matplotlib/_color_data.py b/lib/matplotlib/_color_data.py index 09b0693d89ef..68b9bf4969a4 100644 --- a/lib/matplotlib/_color_data.py +++ b/lib/matplotlib/_color_data.py @@ -29,7 +29,8 @@ # Normalize name to "vega:" to avoid name collisions. -VEGA10_COLORS = {'vega:' + name: value for name, value in VEGA10_COLORS.items()} +VEGA10_COLORS = {'vega:' + name: value for name, + value in VEGA10_COLORS.items()} # This mapping of color names -> hex values is taken from From 56eed352a851252342385110c5713404d6a84903 Mon Sep 17 00:00:00 2001 From: Truong Pham Date: Wed, 26 Oct 2016 11:21:53 -0700 Subject: [PATCH 3/8] Fix pep8 style for vega10 colors descriptions in colors.rst --- doc/users/colors.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/doc/users/colors.rst b/doc/users/colors.rst index 1fccb698b972..eff9f00053da 100644 --- a/doc/users/colors.rst +++ b/doc/users/colors.rst @@ -17,7 +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 ``{'vega10:blue', 'vega10:orange', 'vega10:green', 'vega10:red', 'vega10:purple', 'vega10:brown', 'vega10:pink', 'vega10:gray', 'vega10:olive', 'vega10:cyan'}`` +* one of ``{'vega10:blue', 'vega10:orange', 'vega10:green', 'vega10:red', + 'vega10:purple', 'vega10:brown', 'vega10:pink', 'vega10:gray', + 'vega10:olive', 'vega10:cyan'}`` All string specifications of color are case-insensitive. From ded8d662bd14ed42671178484e5ce72bf647f22e Mon Sep 17 00:00:00 2001 From: Truong Pham Date: Wed, 26 Oct 2016 11:43:01 -0700 Subject: [PATCH 4/8] Change prefix for Vega10 colors from 'vega:_' to 'vega10:_' --- lib/matplotlib/_color_data.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/_color_data.py b/lib/matplotlib/_color_data.py index 68b9bf4969a4..63422dd8f281 100644 --- a/lib/matplotlib/_color_data.py +++ b/lib/matplotlib/_color_data.py @@ -28,8 +28,8 @@ 'cyan': '#17becf'} -# Normalize name to "vega:" to avoid name collisions. -VEGA10_COLORS = {'vega:' + name: value for name, +# Normalize name to "vega10:" to avoid name collisions. +VEGA10_COLORS = {'vega10:' + name: value for name, value in VEGA10_COLORS.items()} From a270ac879944743bf5069a6da573aac4f7889b3a Mon Sep 17 00:00:00 2001 From: Truong Pham Date: Wed, 26 Oct 2016 11:47:22 -0700 Subject: [PATCH 5/8] Change prefix for Vega10 colors from 'vega:' to 'vega10:' in colors.py --- lib/matplotlib/colors.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/colors.py b/lib/matplotlib/colors.py index a6ce47f9c2c3..844b77aa27b4 100644 --- a/lib/matplotlib/colors.py +++ b/lib/matplotlib/colors.py @@ -251,7 +251,8 @@ def to_hex(c, keep_alpha=False): ### Backwards-compatible color-conversion API cnames = CSS4_COLORS -COLOR_NAMES = {'xkcd': XKCD_COLORS, 'css4': CSS4_COLORS, 'vega': VEGA10_COLORS} +COLOR_NAMES = {'xkcd': XKCD_COLORS, 'css4': CSS4_COLORS, + 'vega10': VEGA10_COLORS} hexColorPattern = re.compile("\A#[a-fA-F0-9]{6}\Z") From 89503505d3fb3c22b24a59d5f735fa61a0e6333a Mon Sep 17 00:00:00 2001 From: Truong Pham Date: Fri, 28 Oct 2016 11:53:22 -0700 Subject: [PATCH 6/8] Fix sphinx warning: 'Inline literal start-string without end-string' for vega10 dictionary description in colors.rst --- doc/users/colors.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/users/colors.rst b/doc/users/colors.rst index eff9f00053da..1a8996f4df16 100644 --- a/doc/users/colors.rst +++ b/doc/users/colors.rst @@ -17,9 +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 ``{'vega10:blue', 'vega10:orange', 'vega10:green', 'vega10:red', - 'vega10:purple', 'vega10:brown', 'vega10:pink', 'vega10:gray', - 'vega10:olive', 'vega10:cyan'}`` +* one of ``{'vega10:blue', 'vega10:orange', 'vega10:green', + 'vega10:red', 'vega10:purple', 'vega10:brown', 'vega10:pink', + 'vega10:gray', 'vega10:olive', 'vega10:cyan'}`` All string specifications of color are case-insensitive. From 5ae9cba1fb4c18d4bc2cac1ea1c08b4d489609da Mon Sep 17 00:00:00 2001 From: Truong Pham Date: Tue, 1 Nov 2016 11:21:00 -0700 Subject: [PATCH 7/8] Add test case for Vega10 color --- lib/matplotlib/tests/test_colors.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/tests/test_colors.py b/lib/matplotlib/tests/test_colors.py index ebfc41aa53e3..dcb22eb22ae2 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("vega10:blue") == "#1f77b4" def _sph2cart(theta, phi): From 8b3b97139d791374a3d4d78065d2abb728e4c760 Mon Sep 17 00:00:00 2001 From: Truong Pham Date: Sun, 6 Nov 2016 23:12:04 -0800 Subject: [PATCH 8/8] Change vega10 color package naming convention from: 'vega10:' to 'vega:' --- doc/users/colors.rst | 6 +++--- lib/matplotlib/_color_data.py | 5 ++--- lib/matplotlib/colors.py | 7 +++---- lib/matplotlib/tests/test_colors.py | 2 +- 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/doc/users/colors.rst b/doc/users/colors.rst index 1a8996f4df16..94fe23ad0cbd 100644 --- a/doc/users/colors.rst +++ b/doc/users/colors.rst @@ -17,9 +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 ``{'vega10:blue', 'vega10:orange', 'vega10:green', - 'vega10:red', 'vega10:purple', 'vega10:brown', 'vega10:pink', - 'vega10:gray', 'vega10:olive', 'vega10:cyan'}`` +* 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 63422dd8f281..d6244e1863f5 100644 --- a/lib/matplotlib/_color_data.py +++ b/lib/matplotlib/_color_data.py @@ -15,7 +15,7 @@ 'w': (1, 1, 1)} -VEGA10_COLORS = { +VEGA_COLORS = { 'blue': '#1f77b4', 'orange': '#ff7f0e', 'green': '#2ca02c', @@ -29,8 +29,7 @@ # Normalize name to "vega10:" to avoid name collisions. -VEGA10_COLORS = {'vega10:' + name: value for name, - value in VEGA10_COLORS.items()} +VEGA_COLORS = {'vega:' + name: value for name, value in VEGA_COLORS.items()} # This mapping of color names -> hex values is taken from diff --git a/lib/matplotlib/colors.py b/lib/matplotlib/colors.py index 844b77aa27b4..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, VEGA10_COLORS, CSS4_COLORS, XKCD_COLORS +from ._color_data import BASE_COLORS, VEGA_COLORS, CSS4_COLORS, XKCD_COLORS class _ColorMapping(dict): @@ -86,7 +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(VEGA10_COLORS) +_colors_full_map.update(VEGA_COLORS) _colors_full_map.update(BASE_COLORS) _colors_full_map = _ColorMapping(_colors_full_map) @@ -251,8 +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, - 'vega10': VEGA10_COLORS} +COLOR_NAMES = {'xkcd': XKCD_COLORS, 'css4': CSS4_COLORS, 'vega': VEGA_COLORS} hexColorPattern = re.compile("\A#[a-fA-F0-9]{6}\Z") diff --git a/lib/matplotlib/tests/test_colors.py b/lib/matplotlib/tests/test_colors.py index dcb22eb22ae2..eac575c79013 100644 --- a/lib/matplotlib/tests/test_colors.py +++ b/lib/matplotlib/tests/test_colors.py @@ -575,7 +575,7 @@ def angled_plane(azimuth, elevation, angle, x, y): def test_color_names(): assert mcolors.to_hex("blue") == "#0000ff" assert mcolors.to_hex("xkcd:blue") == "#0343df" - assert mcolors.to_hex("vega10:blue") == "#1f77b4" + assert mcolors.to_hex("vega:blue") == "#1f77b4" def _sph2cart(theta, phi):