From 8ad8ccdfe16904e50991de958820bc7cad94b342 Mon Sep 17 00:00:00 2001 From: Eric Larson Date: Tue, 26 Apr 2022 16:36:30 -0400 Subject: [PATCH 1/5] DOC: Better doc of colors --- examples/color/named_colors.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/examples/color/named_colors.py b/examples/color/named_colors.py index 83206d8e7990..f68031887b13 100644 --- a/examples/color/named_colors.py +++ b/examples/color/named_colors.py @@ -12,6 +12,14 @@ * the :doc:`/tutorials/colors/colors` tutorial; * the `matplotlib.colors` API; * the :doc:`/gallery/color/color_demo`. + +.. contents:: + +---------------------------- +Helper Function for Plotting +---------------------------- +First we define a helper function for making a table of colors, then we use it +on some common color categories. """ from matplotlib.patches import Rectangle @@ -73,11 +81,27 @@ def plot_colortable(colors, title, sort_colors=True, emptycols=0): return fig +############################################################################# +# ----------- +# Base colors +# ----------- + plot_colortable(mcolors.BASE_COLORS, "Base Colors", sort_colors=False, emptycols=1) + +############################################################################# +# --------------- +# Tableau Palette +# --------------- + plot_colortable(mcolors.TABLEAU_COLORS, "Tableau Palette", sort_colors=False, emptycols=2) +############################################################################# +# ---------- +# CSS Colors +# ---------- + # sphinx_gallery_thumbnail_number = 3 plot_colortable(mcolors.CSS4_COLORS, "CSS Colors") From a65d45cfe25eb4cb5e70eee8b6a5fc585abce3db Mon Sep 17 00:00:00 2001 From: Eric Larson Date: Wed, 27 Apr 2022 14:51:51 -0400 Subject: [PATCH 2/5] FIX: Better ref --- examples/color/named_colors.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/examples/color/named_colors.py b/examples/color/named_colors.py index f68031887b13..9c7a48b1642d 100644 --- a/examples/color/named_colors.py +++ b/examples/color/named_colors.py @@ -3,10 +3,7 @@ List of named colors ==================== -This plots a list of the named colors supported in matplotlib. Note that -:ref:`xkcd colors ` are supported as well, but are not listed here -for brevity. - +This plots a list of the named colors supported in matplotlib. For more information on colors in matplotlib see * the :doc:`/tutorials/colors/colors` tutorial; @@ -104,15 +101,17 @@ def plot_colortable(colors, title, sort_colors=True, emptycols=0): # sphinx_gallery_thumbnail_number = 3 plot_colortable(mcolors.CSS4_COLORS, "CSS Colors") - -# Optionally plot the XKCD colors (Caution: will produce large figure) -# xkcd_fig = plot_colortable(mcolors.XKCD_COLORS, "XKCD Colors") -# xkcd_fig.savefig("XKCD_Colors.png") - plt.show() - ############################################################################# +# ----------- +# XKCD Colors +# ----------- +# XKCD colors are supported, but they produce a large figure, so we skip them +# for now. You can use the following code if desired:: +# +# xkcd_fig = plot_colortable(mcolors.XKCD_COLORS, "XKCD Colors") +# xkcd_fig.savefig("XKCD_Colors.png") # # .. admonition:: References # From f41baeedac3510304a68db25282f77f3e2931be7 Mon Sep 17 00:00:00 2001 From: Eric Larson Date: Wed, 27 Apr 2022 14:52:24 -0400 Subject: [PATCH 3/5] FIX: Better ref [skip actions] [skip azp] From 2a07400b85eb2a02aa332b13ecca7401e38ff1e2 Mon Sep 17 00:00:00 2001 From: Eric Larson Date: Wed, 27 Apr 2022 15:44:59 -0400 Subject: [PATCH 4/5] FIX: No need for contents [skip actions] [skip azp] --- 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 9c7a48b1642d..a55bc381cccb 100644 --- a/examples/color/named_colors.py +++ b/examples/color/named_colors.py @@ -10,8 +10,6 @@ * the `matplotlib.colors` API; * the :doc:`/gallery/color/color_demo`. -.. contents:: - ---------------------------- Helper Function for Plotting ---------------------------- From ab990e46881f18ef6d57f51a22e48b55c9716cca Mon Sep 17 00:00:00 2001 From: Eric Larson Date: Thu, 28 Apr 2022 12:23:08 -0400 Subject: [PATCH 5/5] FIX: No title [skip actions] [skip azp] --- examples/color/named_colors.py | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/examples/color/named_colors.py b/examples/color/named_colors.py index a55bc381cccb..59f15e307bd5 100644 --- a/examples/color/named_colors.py +++ b/examples/color/named_colors.py @@ -22,13 +22,12 @@ import matplotlib.colors as mcolors -def plot_colortable(colors, title, sort_colors=True, emptycols=0): +def plot_colortable(colors, sort_colors=True, emptycols=0): cell_width = 212 cell_height = 22 swatch_width = 48 margin = 12 - topmargin = 40 # Sort colors by hue, saturation, value and name. if sort_colors is True: @@ -44,18 +43,17 @@ def plot_colortable(colors, title, sort_colors=True, emptycols=0): nrows = n // ncols + int(n % ncols > 0) width = cell_width * 4 + 2 * margin - height = cell_height * nrows + margin + topmargin + height = cell_height * nrows + 2 * margin dpi = 72 fig, ax = plt.subplots(figsize=(width / dpi, height / dpi), dpi=dpi) fig.subplots_adjust(margin/width, margin/height, - (width-margin)/width, (height-topmargin)/height) + (width-margin)/width, (height-margin)/height) ax.set_xlim(0, cell_width * 4) ax.set_ylim(cell_height * (nrows-0.5), -cell_height/2.) ax.yaxis.set_visible(False) ax.xaxis.set_visible(False) ax.set_axis_off() - ax.set_title(title, fontsize=24, loc="left", pad=10) for i, name in enumerate(names): row = i % nrows @@ -81,16 +79,14 @@ def plot_colortable(colors, title, sort_colors=True, emptycols=0): # Base colors # ----------- -plot_colortable(mcolors.BASE_COLORS, "Base Colors", - sort_colors=False, emptycols=1) +plot_colortable(mcolors.BASE_COLORS, sort_colors=False, emptycols=1) ############################################################################# # --------------- # Tableau Palette # --------------- -plot_colortable(mcolors.TABLEAU_COLORS, "Tableau Palette", - sort_colors=False, emptycols=2) +plot_colortable(mcolors.TABLEAU_COLORS, sort_colors=False, emptycols=2) ############################################################################# # ---------- @@ -98,7 +94,7 @@ def plot_colortable(colors, title, sort_colors=True, emptycols=0): # ---------- # sphinx_gallery_thumbnail_number = 3 -plot_colortable(mcolors.CSS4_COLORS, "CSS Colors") +plot_colortable(mcolors.CSS4_COLORS) plt.show() #############################################################################