From 63b8b6502f400579dd64ed1d45d8989fdd4f2487 Mon Sep 17 00:00:00 2001 From: "Joses W. Ho" Date: Fri, 24 Aug 2018 13:15:27 +0800 Subject: [PATCH 01/25] add Solarized palette --- lib/matplotlib/_color_data.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/lib/matplotlib/_color_data.py b/lib/matplotlib/_color_data.py index 973f4a2f2435..c4604a4e1afc 100644 --- a/lib/matplotlib/_color_data.py +++ b/lib/matplotlib/_color_data.py @@ -1142,3 +1142,26 @@ 'whitesmoke': '#F5F5F5', 'yellow': '#FFFF00', 'yellowgreen': '#9ACD32'} + +# These are the 16 colors of the Solarized palette by Ethan Schoonover. +# See https://ethanschoonover.com/solarized/ +# License: https://github.com/altercation/solarized/blob/master/LICENSE +# Copyright (c) 2011 Ethan Schoonover +SOLARIZED_COLORS = { + 'solarized-base03': '#002b36', + 'solarized-base02': '#073642', + 'solarized-base01': '#586e75', + 'solarized-base00': '#657b83', + 'solarized-base0': '#839496', + 'solarized-base1': '#93a1a1', + 'solarized-base2': '#eee8d5', + 'solarized-base3': '#fdf6e3', + 'solarized-yellow': '#b58900', + 'solarized-orange': '#cb4b16', + 'solarized-red': '#dc322f', + 'solarized-magenta': '#d33682', + 'solarized-violet': '#6c71c4', + 'solarized-blue': '#268bd2', + 'solarized-cyan': '#2aa198', + 'solarized-green': '#859900', +} From befad3c89467836600907913f488511140b2bd31 Mon Sep 17 00:00:00 2001 From: "Joses W. Ho" Date: Fri, 24 Aug 2018 13:15:47 +0800 Subject: [PATCH 02/25] add import solarized colors --- lib/matplotlib/colors.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/colors.py b/lib/matplotlib/colors.py index 82969ed18cb7..4c40cba7cda3 100644 --- a/lib/matplotlib/colors.py +++ b/lib/matplotlib/colors.py @@ -50,7 +50,8 @@ import numpy as np import matplotlib.cbook as cbook -from ._color_data import BASE_COLORS, TABLEAU_COLORS, CSS4_COLORS, XKCD_COLORS +from ._color_data import BASE_COLORS, TABLEAU_COLORS, CSS4_COLORS, \ + XKCD_COLORS, SOLARIZED_COLORS class _ColorMapping(dict): @@ -69,6 +70,7 @@ def __delitem__(self, key): _colors_full_map = {} # Set by reverse priority order. +_colors_full_map.update(SOLARIZED_COLORS) _colors_full_map.update(XKCD_COLORS) _colors_full_map.update({k.replace('grey', 'gray'): v for k, v in XKCD_COLORS.items() From b1e9b57d33f5d3b5fdefd5ea6f7b94155085a104 Mon Sep 17 00:00:00 2001 From: "Joses W. Ho" Date: Fri, 24 Aug 2018 13:16:02 +0800 Subject: [PATCH 03/25] add solarized colors to named color example --- examples/color/named_colors.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/color/named_colors.py b/examples/color/named_colors.py index 5a16c2d813f1..0ebf5968cc1b 100644 --- a/examples/color/named_colors.py +++ b/examples/color/named_colors.py @@ -16,7 +16,8 @@ from matplotlib import colors as mcolors -colors = dict(mcolors.BASE_COLORS, **mcolors.CSS4_COLORS) +colors = dict(mcolors.BASE_COLORS, **mcolors.CSS4_COLORS, + **mcolors.SOLARZIED_COLORS) # Sort colors by hue, saturation, value and name. by_hsv = sorted((tuple(mcolors.rgb_to_hsv(mcolors.to_rgba(color)[:3])), name) From 22f03ee0ffd20f5dacbea0c9616e58e28423d02c Mon Sep 17 00:00:00 2001 From: "Joses W. Ho" Date: Fri, 24 Aug 2018 13:21:52 +0800 Subject: [PATCH 04/25] add Solarized palette writeup to whats_new --- doc/users/whats_new.rst | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/doc/users/whats_new.rst b/doc/users/whats_new.rst index 4f89851070b5..9090e2b3058f 100644 --- a/doc/users/whats_new.rst +++ b/doc/users/whats_new.rst @@ -86,6 +86,13 @@ wrap around, they are a good choice for cyclic data such as phase angles, compass directions, or time of day. Like *viridis*, *twilight* is perceptually uniform and colorblind friendly. +Add Solarized palette to named matplotlib colors +------------------------------------------------- +Ethan Schoonover's `Solarized palette Date: Fri, 24 Aug 2018 13:34:42 +0800 Subject: [PATCH 05/25] fix typo --- examples/color/named_colors.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/color/named_colors.py b/examples/color/named_colors.py index 0ebf5968cc1b..72c852e29a3c 100644 --- a/examples/color/named_colors.py +++ b/examples/color/named_colors.py @@ -17,7 +17,7 @@ colors = dict(mcolors.BASE_COLORS, **mcolors.CSS4_COLORS, - **mcolors.SOLARZIED_COLORS) + **mcolors.SOLARIZED_COLORS) # Sort colors by hue, saturation, value and name. by_hsv = sorted((tuple(mcolors.rgb_to_hsv(mcolors.to_rgba(color)[:3])), name) From b329729bafe109dcb0c28832ea1bd6090fd716d0 Mon Sep 17 00:00:00 2001 From: "Joses W. Ho" Date: Fri, 24 Aug 2018 17:13:46 +0800 Subject: [PATCH 06/25] align dict with above dict; change "solarized-" to "solarized:" --- lib/matplotlib/_color_data.py | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/lib/matplotlib/_color_data.py b/lib/matplotlib/_color_data.py index c4604a4e1afc..5a50ca71e578 100644 --- a/lib/matplotlib/_color_data.py +++ b/lib/matplotlib/_color_data.py @@ -1148,20 +1148,20 @@ # License: https://github.com/altercation/solarized/blob/master/LICENSE # Copyright (c) 2011 Ethan Schoonover SOLARIZED_COLORS = { - 'solarized-base03': '#002b36', - 'solarized-base02': '#073642', - 'solarized-base01': '#586e75', - 'solarized-base00': '#657b83', - 'solarized-base0': '#839496', - 'solarized-base1': '#93a1a1', - 'solarized-base2': '#eee8d5', - 'solarized-base3': '#fdf6e3', - 'solarized-yellow': '#b58900', - 'solarized-orange': '#cb4b16', - 'solarized-red': '#dc322f', - 'solarized-magenta': '#d33682', - 'solarized-violet': '#6c71c4', - 'solarized-blue': '#268bd2', - 'solarized-cyan': '#2aa198', - 'solarized-green': '#859900', + 'solarized:base03': '#002b36', + 'solarized:base02': '#073642', + 'solarized:base01': '#586e75', + 'solarized:base00': '#657b83', + 'solarized:base0': '#839496', + 'solarized:base1': '#93a1a1', + 'solarized:base2': '#eee8d5', + 'solarized:base3': '#fdf6e3', + 'solarized:yellow': '#b58900', + 'solarized:orange': '#cb4b16', + 'solarized:red': '#dc322f', + 'solarized:magenta': '#d33682', + 'solarized:violet': '#6c71c4', + 'solarized:blue': '#268bd2', + 'solarized:cyan': '#2aa198', + 'solarized:green': '#859900', } From 1dc142d8e1cf609da5c1215046318d5cd326f755 Mon Sep 17 00:00:00 2001 From: "Joses W. Ho" Date: Fri, 24 Aug 2018 17:14:55 +0800 Subject: [PATCH 07/25] align import --- lib/matplotlib/colors.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/colors.py b/lib/matplotlib/colors.py index 4c40cba7cda3..1d6cf6a3a58d 100644 --- a/lib/matplotlib/colors.py +++ b/lib/matplotlib/colors.py @@ -50,8 +50,8 @@ import numpy as np import matplotlib.cbook as cbook -from ._color_data import BASE_COLORS, TABLEAU_COLORS, CSS4_COLORS, \ - XKCD_COLORS, SOLARIZED_COLORS +from ._color_data import (BASE_COLORS, TABLEAU_COLORS, CSS4_COLORS, + XKCD_COLORS, SOLARIZED_COLORS) class _ColorMapping(dict): From c5cd04b2807b6af46d66059bfd7c0c6d167f629f Mon Sep 17 00:00:00 2001 From: "Joses W. Ho" Date: Fri, 24 Aug 2018 17:15:34 +0800 Subject: [PATCH 08/25] align within parenthesis --- examples/color/named_colors.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/color/named_colors.py b/examples/color/named_colors.py index 72c852e29a3c..816152c87873 100644 --- a/examples/color/named_colors.py +++ b/examples/color/named_colors.py @@ -17,7 +17,7 @@ colors = dict(mcolors.BASE_COLORS, **mcolors.CSS4_COLORS, - **mcolors.SOLARIZED_COLORS) + **mcolors.SOLARIZED_COLORS) # Sort colors by hue, saturation, value and name. by_hsv = sorted((tuple(mcolors.rgb_to_hsv(mcolors.to_rgba(color)[:3])), name) From 4f766d3465c19c0d0919a2ca6c0a296dcb650d95 Mon Sep 17 00:00:00 2001 From: "Joses W. Ho" Date: Fri, 24 Aug 2018 17:18:05 +0800 Subject: [PATCH 09/25] fix reference to solarized colors --- doc/users/whats_new.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/users/whats_new.rst b/doc/users/whats_new.rst index 9090e2b3058f..f5c5febc8b9e 100644 --- a/doc/users/whats_new.rst +++ b/doc/users/whats_new.rst @@ -90,8 +90,8 @@ Add Solarized palette to named matplotlib colors ------------------------------------------------- Ethan Schoonover's `Solarized palette Date: Sat, 25 Aug 2018 14:52:26 +0800 Subject: [PATCH 10/25] update named colors example Display Tableau colors, and now each color group should get its own figure --- examples/color/named_colors.py | 90 +++++++++++++++++++++------------- 1 file changed, 55 insertions(+), 35 deletions(-) diff --git a/examples/color/named_colors.py b/examples/color/named_colors.py index 816152c87873..a7fd9e949ba1 100644 --- a/examples/color/named_colors.py +++ b/examples/color/named_colors.py @@ -11,54 +11,74 @@ * the `matplotlib.colors` API; * the :doc:`/gallery/color/color_demo`. """ - -import matplotlib.pyplot as plt from matplotlib import colors as mcolors -colors = dict(mcolors.BASE_COLORS, **mcolors.CSS4_COLORS, - **mcolors.SOLARIZED_COLORS) +# First, we define a custom plotting function that accepts a dictionary +# from one of matplotlib's named color palettes. +def plot_colors(colors, title, fig_size, sort_colors=True, ncols=4): + + import matplotlib.pyplot as plt + from matplotlib.colors import rgb_to_hsv, to_rgba + + # Sort colors by hue, saturation, value and name. + by_hsv = ((tuple(rgb_to_hsv(to_rgba(color)[:3])), name) + for name, color in colors.items()) + if sort_colors is True: + by_hsv = sorted(by_hsv) + names = [name for hsv, name in by_hsv] + + n = len(names) + nrows = n // ncols + + fig, ax = plt.subplots(figsize=fig_size) + + # Get height and width + X, Y = fig.get_dpi() * fig.get_size_inches() + h = Y / (nrows + 1) + w = X / ncols + + for i, name in enumerate(names): + row = i % nrows + col = i // nrows + y = Y - (row * h) - h + + xi_line = w * (col + 0.05) + xf_line = w * (col + 0.25) + xi_text = w * (col + 0.3) + + ax.text(xi_text, y, name, fontsize=(h * 0.5), + horizontalalignment='left', + verticalalignment='center') -# Sort colors by hue, saturation, value and name. -by_hsv = sorted((tuple(mcolors.rgb_to_hsv(mcolors.to_rgba(color)[:3])), name) - for name, color in colors.items()) -sorted_names = [name for hsv, name in by_hsv] + ax.hlines(y + h * 0.1, xi_line, xf_line, + color=colors[name], linewidth=(h * 0.6)) -n = len(sorted_names) -ncols = 4 -nrows = n // ncols + ax.set_xlim(0, X) + ax.set_ylim(0, Y) + ax.set_axis_off() -fig, ax = plt.subplots(figsize=(9, 8)) + fig.subplots_adjust(left=0, right=1, + top=1, bottom=0, + hspace=0, wspace=0) -# Get height and width -X, Y = fig.get_dpi() * fig.get_size_inches() -h = Y / (nrows + 1) -w = X / ncols + fig.suptitle(title, y=1.07, fontsize=20) -for i, name in enumerate(sorted_names): - row = i % nrows - col = i // nrows - y = Y - (row * h) - h + plt.tight_layout() + plt.show() - xi_line = w * (col + 0.05) - xf_line = w * (col + 0.25) - xi_text = w * (col + 0.3) - ax.text(xi_text, y, name, fontsize=(h * 0.5), - horizontalalignment='left', - verticalalignment='center') +plot_colors(mcolors.BASE_COLORS, "Base Colors", + fig_size=(9, 1.5)) - ax.hlines(y + h * 0.1, xi_line, xf_line, - color=colors[name], linewidth=(h * 0.6)) +plot_colors(mcolors.CSS4_COLORS, "CSS Colors", + fig_size=(9, 10)) -ax.set_xlim(0, X) -ax.set_ylim(0, Y) -ax.set_axis_off() +plot_colors(mcolors.SOLARIZED_COLORS, "Solarized Palette", + fig_size=(9, 4), ncols=2, sort_colors=False) -fig.subplots_adjust(left=0, right=1, - top=1, bottom=0, - hspace=0, wspace=0) -plt.show() +plot_colors(mcolors.TABLEAU_COLORS, "Tableau Palette", + fig_size=(9, 3.2), ncols=2) ############################################################################# # From 72716abc84b391753348fa63c78f2243d4bc8a29 Mon Sep 17 00:00:00 2001 From: "Joses W. Ho" Date: Mon, 27 Aug 2018 00:55:39 +0800 Subject: [PATCH 11/25] align swatches; standardize swatch size and font size --- examples/color/named_colors.py | 35 +++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/examples/color/named_colors.py b/examples/color/named_colors.py index a7fd9e949ba1..4b56ea47ba72 100644 --- a/examples/color/named_colors.py +++ b/examples/color/named_colors.py @@ -16,7 +16,7 @@ # First, we define a custom plotting function that accepts a dictionary # from one of matplotlib's named color palettes. -def plot_colors(colors, title, fig_size, sort_colors=True, ncols=4): +def plot_colors(colors, title, swatch_width=3, swatch_height=1, sort_colors=True, ncols=4): import matplotlib.pyplot as plt from matplotlib.colors import rgb_to_hsv, to_rgba @@ -30,8 +30,12 @@ def plot_colors(colors, title, fig_size, sort_colors=True, ncols=4): n = len(names) nrows = n // ncols + if n % ncols > 0: + nrows += 1 - fig, ax = plt.subplots(figsize=fig_size) + x_inches = swatch_width * ncols + y_inches = swatch_height * nrows + fig, ax = plt.subplots(figsize=(x_inches, y_inches)) # Get height and width X, Y = fig.get_dpi() * fig.get_size_inches() @@ -43,16 +47,17 @@ def plot_colors(colors, title, fig_size, sort_colors=True, ncols=4): col = i // nrows y = Y - (row * h) - h - xi_line = w * (col + 0.05) - xf_line = w * (col + 0.25) - xi_text = w * (col + 0.3) + swatch_start_x = w * (col + 0.05) + swatch_end_x = w * (col + 0.3) + text_pos_x = w * (col + 0.35) - ax.text(xi_text, y, name, fontsize=(h * 0.5), + ax.text(text_pos_x, y, name, fontsize=15, horizontalalignment='left', verticalalignment='center') - ax.hlines(y + h * 0.1, xi_line, xf_line, - color=colors[name], linewidth=(h * 0.6)) + ax.hlines(y, + swatch_start_x, swatch_end_x, + color=colors[name], linewidth=20) ax.set_xlim(0, X) ax.set_ylim(0, Y) @@ -62,23 +67,19 @@ def plot_colors(colors, title, fig_size, sort_colors=True, ncols=4): top=1, bottom=0, hspace=0, wspace=0) - fig.suptitle(title, y=1.07, fontsize=20) + plt.title(title, fontsize=25) plt.tight_layout() plt.show() -plot_colors(mcolors.BASE_COLORS, "Base Colors", - fig_size=(9, 1.5)) +plot_colors(mcolors.BASE_COLORS, "Base Colors") -plot_colors(mcolors.CSS4_COLORS, "CSS Colors", - fig_size=(9, 10)) +plot_colors(mcolors.CSS4_COLORS, "CSS Colors") -plot_colors(mcolors.SOLARIZED_COLORS, "Solarized Palette", - fig_size=(9, 4), ncols=2, sort_colors=False) +plot_colors(mcolors.SOLARIZED_COLORS, "Solarized Palette", sort_colors=False) -plot_colors(mcolors.TABLEAU_COLORS, "Tableau Palette", - fig_size=(9, 3.2), ncols=2) +plot_colors(mcolors.TABLEAU_COLORS, "Tableau Palette") ############################################################################# # From cec44bbfe48756e9306233120e4502d09b855e41 Mon Sep 17 00:00:00 2001 From: "Joses W. Ho" Date: Mon, 27 Aug 2018 11:18:44 +0800 Subject: [PATCH 12/25] better control of grid layout --- examples/color/named_colors.py | 73 ++++++++++++++++++---------------- 1 file changed, 38 insertions(+), 35 deletions(-) diff --git a/examples/color/named_colors.py b/examples/color/named_colors.py index 4b56ea47ba72..43c842f3670c 100644 --- a/examples/color/named_colors.py +++ b/examples/color/named_colors.py @@ -14,13 +14,18 @@ from matplotlib import colors as mcolors + # First, we define a custom plotting function that accepts a dictionary # from one of matplotlib's named color palettes. -def plot_colors(colors, title, swatch_width=3, swatch_height=1, sort_colors=True, ncols=4): - +def plot_colortable(colors, title, sort_colors=True, order="by_row", ncols=4): import matplotlib.pyplot as plt from matplotlib.colors import rgb_to_hsv, to_rgba + extra_rows = 2 # additional space for title + cell_width = 225 + cell_height = 30 + swatch_width = 50 + # Sort colors by hue, saturation, value and name. by_hsv = ((tuple(rgb_to_hsv(to_rgba(color)[:3])), name) for name, color in colors.items()) @@ -29,57 +34,55 @@ def plot_colors(colors, title, swatch_width=3, swatch_height=1, sort_colors=True names = [name for hsv, name in by_hsv] n = len(names) - nrows = n // ncols + nrows = (n + 1) // ncols if n % ncols > 0: nrows += 1 - x_inches = swatch_width * ncols - y_inches = swatch_height * nrows - fig, ax = plt.subplots(figsize=(x_inches, y_inches)) + width = cell_width * ncols + height = cell_height * (nrows + extra_rows) + dpi = 72 + fig, ax = plt.subplots(figsize=(width / dpi, height / dpi), + dpi=dpi) - # Get height and width - X, Y = fig.get_dpi() * fig.get_size_inches() - h = Y / (nrows + 1) - w = X / ncols + ax.set_xlim(0, width) + ax.set_ylim(height, 0) + ax.yaxis.set_visible(False) + ax.xaxis.set_visible(False) + ax.set_axis_off() + ax.text(0, cell_height, title, fontsize=20) for i, name in enumerate(names): - row = i % nrows - col = i // nrows - y = Y - (row * h) - h + if order == "by_row": + row = i // ncols + col = i % ncols + elif order == 'by_column': + row = i % nrows + col = i // nrows + + y = (row + extra_rows) * cell_height - swatch_start_x = w * (col + 0.05) - swatch_end_x = w * (col + 0.3) - text_pos_x = w * (col + 0.35) + swatch_start_x = cell_width * col + swatch_end_x = cell_width * col + swatch_width + text_pos_x = cell_width * col + swatch_width + 5 - ax.text(text_pos_x, y, name, fontsize=15, + ax.text(text_pos_x, y, name, fontsize=12, horizontalalignment='left', verticalalignment='center') - ax.hlines(y, - swatch_start_x, swatch_end_x, + ax.hlines(y, swatch_start_x, swatch_end_x, color=colors[name], linewidth=20) - - ax.set_xlim(0, X) - ax.set_ylim(0, Y) - ax.set_axis_off() - - fig.subplots_adjust(left=0, right=1, - top=1, bottom=0, - hspace=0, wspace=0) - - plt.title(title, fontsize=25) - - plt.tight_layout() + plt.show() -plot_colors(mcolors.BASE_COLORS, "Base Colors") +plot_colortable(mcolors.BASE_COLORS, "Base Colors", sort_colors=False) -plot_colors(mcolors.CSS4_COLORS, "CSS Colors") +plot_colortable(mcolors.CSS4_COLORS, "CSS Colors") -plot_colors(mcolors.SOLARIZED_COLORS, "Solarized Palette", sort_colors=False) +plot_colortable(SOLARIZED_COLORS, "Solarized Palette", order='by_column', + sort_colors=False) -plot_colors(mcolors.TABLEAU_COLORS, "Tableau Palette") +plot_colortable(mcolors.TABLEAU_COLORS, "Tableau Palette") ############################################################################# # From 57c7d00d48057d18edb73170171655cb20711577 Mon Sep 17 00:00:00 2001 From: "Joses W. Ho" Date: Mon, 27 Aug 2018 11:26:53 +0800 Subject: [PATCH 13/25] fix missing `mcolors.` --- examples/color/named_colors.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/color/named_colors.py b/examples/color/named_colors.py index 43c842f3670c..9d7f613f324b 100644 --- a/examples/color/named_colors.py +++ b/examples/color/named_colors.py @@ -71,7 +71,7 @@ def plot_colortable(colors, title, sort_colors=True, order="by_row", ncols=4): ax.hlines(y, swatch_start_x, swatch_end_x, color=colors[name], linewidth=20) - + plt.show() @@ -79,7 +79,7 @@ def plot_colortable(colors, title, sort_colors=True, order="by_row", ncols=4): plot_colortable(mcolors.CSS4_COLORS, "CSS Colors") -plot_colortable(SOLARIZED_COLORS, "Solarized Palette", order='by_column', +plot_colortable(mcolors.SOLARIZED_COLORS, "Solarized Palette", order='by_column', sort_colors=False) plot_colortable(mcolors.TABLEAU_COLORS, "Tableau Palette") From da7d5be0405a0c3eca483615ef5c6f6d0bc12068 Mon Sep 17 00:00:00 2001 From: "Joses W. Ho" Date: Mon, 27 Aug 2018 11:28:58 +0800 Subject: [PATCH 14/25] code lint --- examples/color/named_colors.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/color/named_colors.py b/examples/color/named_colors.py index 9d7f613f324b..30185c8c6b50 100644 --- a/examples/color/named_colors.py +++ b/examples/color/named_colors.py @@ -79,8 +79,8 @@ def plot_colortable(colors, title, sort_colors=True, order="by_row", ncols=4): plot_colortable(mcolors.CSS4_COLORS, "CSS Colors") -plot_colortable(mcolors.SOLARIZED_COLORS, "Solarized Palette", order='by_column', - sort_colors=False) +plot_colortable(mcolors.SOLARIZED_COLORS, "Solarized Palette", + order='by_column', sort_colors=False) plot_colortable(mcolors.TABLEAU_COLORS, "Tableau Palette") From 36d14cb982f1ddebc8b3d14de7349ea2d42005e6 Mon Sep 17 00:00:00 2001 From: "Joses W. Ho" Date: Mon, 27 Aug 2018 11:29:09 +0800 Subject: [PATCH 15/25] removed unused functions in references --- examples/color/named_colors.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/examples/color/named_colors.py b/examples/color/named_colors.py index 30185c8c6b50..7691280e1d23 100644 --- a/examples/color/named_colors.py +++ b/examples/color/named_colors.py @@ -98,7 +98,5 @@ def plot_colortable(colors, title, sort_colors=True, order="by_row", ncols=4): matplotlib.colors matplotlib.colors.rgb_to_hsv matplotlib.colors.to_rgba -matplotlib.figure.Figure.get_size_inches -matplotlib.figure.Figure.subplots_adjust matplotlib.axes.Axes.text matplotlib.axes.Axes.hlines From 7d9f6706404cad775d029a799078ad59778a67de Mon Sep 17 00:00:00 2001 From: "Joses W. Ho" Date: Mon, 27 Aug 2018 12:07:42 +0800 Subject: [PATCH 16/25] add descriptions as inline comments --- examples/color/named_colors.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/examples/color/named_colors.py b/examples/color/named_colors.py index 7691280e1d23..b9d7135eab21 100644 --- a/examples/color/named_colors.py +++ b/examples/color/named_colors.py @@ -74,14 +74,19 @@ def plot_colortable(colors, title, sort_colors=True, order="by_row", ncols=4): plt.show() - +# Display the 8 base colors in matplotlib. plot_colortable(mcolors.BASE_COLORS, "Base Colors", sort_colors=False) +# Displays named colors as defined by the CSS specification. +# For more on CSS colors, see https://www.w3.org/TR/css-color-4/ plot_colortable(mcolors.CSS4_COLORS, "CSS Colors") +# The Solarized palette is a 16-color palette designed for screen use. +# For more information, see https://ethanschoonover.com/solarized/ plot_colortable(mcolors.SOLARIZED_COLORS, "Solarized Palette", order='by_column', sort_colors=False) +# This displays the classic 10-color default palette in Tableau. plot_colortable(mcolors.TABLEAU_COLORS, "Tableau Palette") ############################################################################# From 6138137fe04d7673cb70c3fa2b1b0b3ec1348adc Mon Sep 17 00:00:00 2001 From: "Joses W. Ho" Date: Wed, 29 Aug 2018 20:41:18 +0800 Subject: [PATCH 17/25] revert as per issuecomment-416700193 --- examples/color/named_colors.py | 59 ++++++++++++++++------------------ 1 file changed, 27 insertions(+), 32 deletions(-) diff --git a/examples/color/named_colors.py b/examples/color/named_colors.py index 4b56ea47ba72..06d9c7ce4deb 100644 --- a/examples/color/named_colors.py +++ b/examples/color/named_colors.py @@ -16,11 +16,16 @@ # First, we define a custom plotting function that accepts a dictionary # from one of matplotlib's named color palettes. -def plot_colors(colors, title, swatch_width=3, swatch_height=1, sort_colors=True, ncols=4): +def plot_colors(colors, title, sort_colors=True, ncols=4): import matplotlib.pyplot as plt from matplotlib.colors import rgb_to_hsv, to_rgba + extra_rows = 2 # additional space for title + cell_width = 225 + cell_height = 30 + swatch_width = 50 + # Sort colors by hue, saturation, value and name. by_hsv = ((tuple(rgb_to_hsv(to_rgba(color)[:3])), name) for name, color in colors.items()) @@ -29,57 +34,47 @@ def plot_colors(colors, title, swatch_width=3, swatch_height=1, sort_colors=True names = [name for hsv, name in by_hsv] n = len(names) - nrows = n // ncols - if n % ncols > 0: - nrows += 1 + nrows = (n + 1) // ncols - x_inches = swatch_width * ncols - y_inches = swatch_height * nrows - fig, ax = plt.subplots(figsize=(x_inches, y_inches)) + width = cell_width * ncols + height = cell_height * (nrows + extra_rows) + dpi = 72 + fig, ax = plt.subplots(figsize=(width / dpi, height / dpi), dpi=dpi) - # Get height and width - X, Y = fig.get_dpi() * fig.get_size_inches() - h = Y / (nrows + 1) - w = X / ncols + ax.set_xlim(0, width) + ax.set_ylim(height, 0) + ax.yaxis.set_visible(False) + ax.xaxis.set_visible(False) + ax.set_axis_off() + ax.text(0, cell_height, title, fontsize=20) for i, name in enumerate(names): row = i % nrows col = i // nrows - y = Y - (row * h) - h + y = (row + extra_rows) * cell_height - swatch_start_x = w * (col + 0.05) - swatch_end_x = w * (col + 0.3) - text_pos_x = w * (col + 0.35) + swatch_start_x = cell_width * col + swatch_end_x = cell_width * col + swatch_width + text_pos_x = cell_width * col + swatch_width + 5 - ax.text(text_pos_x, y, name, fontsize=15, + ax.text(text_pos_x, y, name, fontsize=14, horizontalalignment='left', verticalalignment='center') - ax.hlines(y, - swatch_start_x, swatch_end_x, + ax.hlines(y, swatch_start_x, swatch_end_x, color=colors[name], linewidth=20) - - ax.set_xlim(0, X) - ax.set_ylim(0, Y) - ax.set_axis_off() - - fig.subplots_adjust(left=0, right=1, - top=1, bottom=0, - hspace=0, wspace=0) - - plt.title(title, fontsize=25) - - plt.tight_layout() plt.show() -plot_colors(mcolors.BASE_COLORS, "Base Colors") +plot_colors(mcolors.BASE_COLORS, "Base Colors", sort_colors=False, + ncols=3) plot_colors(mcolors.CSS4_COLORS, "CSS Colors") plot_colors(mcolors.SOLARIZED_COLORS, "Solarized Palette", sort_colors=False) -plot_colors(mcolors.TABLEAU_COLORS, "Tableau Palette") +plot_colors(mcolors.TABLEAU_COLORS, "Tableau Palette", sort_colors=False, + ncols=2) ############################################################################# # From 59761d7fc900c9aa22049098b8650e22d34c9bd5 Mon Sep 17 00:00:00 2001 From: "Joses W. Ho" Date: Wed, 29 Aug 2018 23:09:24 +0800 Subject: [PATCH 18/25] moved solarized writeup from whats_new to next_whats_new --- doc/users/next_whats_new/solarized_palette.rst | 6 ++++++ doc/users/whats_new.rst | 7 ------- 2 files changed, 6 insertions(+), 7 deletions(-) create mode 100644 doc/users/next_whats_new/solarized_palette.rst diff --git a/doc/users/next_whats_new/solarized_palette.rst b/doc/users/next_whats_new/solarized_palette.rst new file mode 100644 index 000000000000..282f2b1bca91 --- /dev/null +++ b/doc/users/next_whats_new/solarized_palette.rst @@ -0,0 +1,6 @@ +Solarized palette are now named matplotlib colors +------------------------------------------------- +Ethan Schoonover's `Solarized palette Date: Wed, 29 Aug 2018 23:09:46 +0800 Subject: [PATCH 19/25] add mention of Solarized to colors.py module docstring --- lib/matplotlib/colors.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/matplotlib/colors.py b/lib/matplotlib/colors.py index 1d6cf6a3a58d..d3fb0ef2c65d 100644 --- a/lib/matplotlib/colors.py +++ b/lib/matplotlib/colors.py @@ -36,6 +36,12 @@ '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); +* one of ``{'solarized:base03', 'solarized:base02', 'solarized:base01', + 'solarized:base00', 'solarized:base0', 'solarized:base1', 'solarized:base2', + 'solarized:base3', 'solarized:yellow', 'solarized:orange', 'solarized:red', + 'solarized:magenta', 'solarized:violet', 'solarized:blue', 'solarized:cyan', + 'solarized:green'}`` which are the colors from Ethan + Schoonover's `Solarized palette `_; * a "CN" color spec, i.e. `'C'` followed by a single digit, which is an index into the default property cycle (``matplotlib.rcParams['axes.prop_cycle']``); the indexing occurs at artist creation time and defaults to black if the From fa9fda581d72ecd53ad6f93265c88a9367b6d140 Mon Sep 17 00:00:00 2001 From: "Joses W. Ho" Date: Wed, 29 Aug 2018 23:38:23 +0800 Subject: [PATCH 20/25] fix typo --- examples/color/named_colors.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/color/named_colors.py b/examples/color/named_colors.py index ab16ef427d9c..7055d0ced4fc 100644 --- a/examples/color/named_colors.py +++ b/examples/color/named_colors.py @@ -76,7 +76,7 @@ def plot_colors(colors, title, sort_colors=True, ncols=4): # The Solarized palette is a 16-color palette designed for screen use. # For more information, see https://ethanschoonover.com/solarized/ -plot_colortable(mcolors.SOLARIZED_COLORS, "Solarized Palette", +plot_colors(mcolors.SOLARIZED_COLORS, "Solarized Palette", order='by_column', sort_colors=False) # This displays the classic 10-color default palette in Tableau. From cf70a3d15915351fa43164fe93e122abfe03c3f4 Mon Sep 17 00:00:00 2001 From: "Joses W. Ho" Date: Thu, 30 Aug 2018 00:13:11 +0800 Subject: [PATCH 21/25] fix another typo --- examples/color/named_colors.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/color/named_colors.py b/examples/color/named_colors.py index 7055d0ced4fc..bcfbcd7982ad 100644 --- a/examples/color/named_colors.py +++ b/examples/color/named_colors.py @@ -77,7 +77,7 @@ def plot_colors(colors, title, sort_colors=True, ncols=4): # The Solarized palette is a 16-color palette designed for screen use. # For more information, see https://ethanschoonover.com/solarized/ plot_colors(mcolors.SOLARIZED_COLORS, "Solarized Palette", - order='by_column', sort_colors=False) + sort_colors=False) # This displays the classic 10-color default palette in Tableau. plot_colors(mcolors.TABLEAU_COLORS, "Tableau Palette", sort_colors=False, From 88c05e77e2c5b54a3348eec698d5b472d49ad0b2 Mon Sep 17 00:00:00 2001 From: "Joses W. Ho" Date: Thu, 30 Aug 2018 00:54:47 +0800 Subject: [PATCH 22/25] fix identation in docstring --- lib/matplotlib/colors.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/colors.py b/lib/matplotlib/colors.py index d3fb0ef2c65d..02a44cf5854a 100644 --- a/lib/matplotlib/colors.py +++ b/lib/matplotlib/colors.py @@ -40,8 +40,8 @@ 'solarized:base00', 'solarized:base0', 'solarized:base1', 'solarized:base2', 'solarized:base3', 'solarized:yellow', 'solarized:orange', 'solarized:red', 'solarized:magenta', 'solarized:violet', 'solarized:blue', 'solarized:cyan', - 'solarized:green'}`` which are the colors from Ethan - Schoonover's `Solarized palette `_; + 'solarized:green'}`` which are the colors from Ethan Schoonover's ` + Solarized palette `_;. * a "CN" color spec, i.e. `'C'` followed by a single digit, which is an index into the default property cycle (``matplotlib.rcParams['axes.prop_cycle']``); the indexing occurs at artist creation time and defaults to black if the From 6dbfb50e14671596c75da86cb9f8cc6c63f30067 Mon Sep 17 00:00:00 2001 From: "Joses W. Ho" Date: Thu, 30 Aug 2018 00:55:30 +0800 Subject: [PATCH 23/25] fix broekn rst hyperlink --- lib/matplotlib/colors.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/colors.py b/lib/matplotlib/colors.py index 02a44cf5854a..ad35a2c130d9 100644 --- a/lib/matplotlib/colors.py +++ b/lib/matplotlib/colors.py @@ -40,8 +40,8 @@ 'solarized:base00', 'solarized:base0', 'solarized:base1', 'solarized:base2', 'solarized:base3', 'solarized:yellow', 'solarized:orange', 'solarized:red', 'solarized:magenta', 'solarized:violet', 'solarized:blue', 'solarized:cyan', - 'solarized:green'}`` which are the colors from Ethan Schoonover's ` - Solarized palette `_;. + 'solarized:green'}`` which are the colors from Ethan Schoonover's + `Solarized palette `_;. * a "CN" color spec, i.e. `'C'` followed by a single digit, which is an index into the default property cycle (``matplotlib.rcParams['axes.prop_cycle']``); the indexing occurs at artist creation time and defaults to black if the From 00f5c60aec62acc820fb33632acc802221c26f68 Mon Sep 17 00:00:00 2001 From: "Joses W. Ho" Date: Thu, 30 Aug 2018 09:51:01 +0800 Subject: [PATCH 24/25] add solarized description to docstring --- examples/color/color_demo.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/examples/color/color_demo.py b/examples/color/color_demo.py index d366f0a1b959..b7a0d6708556 100644 --- a/examples/color/color_demo.py +++ b/examples/color/color_demo.py @@ -3,7 +3,7 @@ Color Demo ========== -Matplotlib gives you 8 ways to specify colors, +Matplotlib gives you 9 ways to specify colors, 1) an RGB or RGBA tuple of float values in ``[0, 1]`` (e.g. ``(0.1, 0.2, 0.5)`` or ``(0.1, 0.2, 0.5, 0.3)``). RGBA is short for Red, Green, Blue, Alpha; @@ -23,6 +23,12 @@ 'tab:red', 'tab:purple', 'tab:brown', 'tab:pink', 'tab:gray', 'tab:olive', 'tab:cyan'}`` which are the Tableau Colors from the 'tab10' categorical palette (which is the default color cycle); +9) one of ``{'solarized:base03', 'solarized:base02', 'solarized:base01', + 'solarized:base00', 'solarized:base0', 'solarized:base1', 'solarized:base2', + 'solarized:base3', 'solarized:yellow', 'solarized:orange', 'solarized:red', + 'solarized:magenta', 'solarized:violet', 'solarized:blue', 'solarized:cyan', + 'solarized:green'}`` which are the colors from Ethan Schoonover's + `Solarized palette `_;. For more information on colors in matplotlib see From 3dabeaed83532fd1c97125fa5342b9e5a8e385a9 Mon Sep 17 00:00:00 2001 From: "Joses W. Ho" Date: Thu, 30 Aug 2018 09:51:21 +0800 Subject: [PATCH 25/25] uncomment next_whats_new TOC chunk --- doc/users/whats_new.rst | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/doc/users/whats_new.rst b/doc/users/whats_new.rst index 4f89851070b5..6fbff58f59f4 100644 --- a/doc/users/whats_new.rst +++ b/doc/users/whats_new.rst @@ -15,12 +15,12 @@ revision, see the :ref:`github-stats`. For a release, add a new section after this, then comment out the include and toctree below by indenting them. Uncomment them after the release. - .. include:: next_whats_new/README.rst - .. toctree:: - :glob: - :maxdepth: 1 +.. include:: next_whats_new/README.rst + .. toctree:: + :glob: + :maxdepth: 1 - next_whats_new/* + next_whats_new/* Ability to scale axis by a fixed order of magnitude ---------------------------------------------------