From 49d882dc9eaae7132cf0936a4e71b567f87c4e02 Mon Sep 17 00:00:00 2001 From: Adam Date: Mon, 3 Feb 2020 22:25:54 +0000 Subject: [PATCH 1/2] Convert named_colors example to use Rectangle In line with #15614, this changes the named_colors example in the docs to use a Rectangle rather than drawing lines. This should make it more flexible to update in future. --- examples/color/named_colors.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/examples/color/named_colors.py b/examples/color/named_colors.py index 7175707c0ce4..33c2b3ed137b 100644 --- a/examples/color/named_colors.py +++ b/examples/color/named_colors.py @@ -14,6 +14,7 @@ * the :doc:`/gallery/color/color_demo`. """ +from matplotlib.patches import Rectangle import matplotlib.pyplot as plt import matplotlib.colors as mcolors @@ -59,15 +60,16 @@ def plot_colortable(colors, title, sort_colors=True, emptycols=0): y = row * cell_height swatch_start_x = cell_width * col - swatch_end_x = cell_width * col + swatch_width text_pos_x = cell_width * col + swatch_width + 7 ax.text(text_pos_x, y, name, fontsize=14, horizontalalignment='left', verticalalignment='center') - ax.hlines(y, swatch_start_x, swatch_end_x, - color=colors[name], linewidth=18) + ax.add_patch( + Rectangle(xy=(swatch_start_x, y-9), width=swatch_width, + height=18, fill=True, facecolor=colors[name]) + ) return fig @@ -103,4 +105,4 @@ def plot_colortable(colors, title, sort_colors=True, emptycols=0): matplotlib.figure.Figure.get_size_inches matplotlib.figure.Figure.subplots_adjust matplotlib.axes.Axes.text -matplotlib.axes.Axes.hlines +matplotlib.patches.Rectangle From abf26ec4e3d15e43222b9ce8f61204a5b841b7a1 Mon Sep 17 00:00:00 2001 From: Adam Ruszkowski Date: Tue, 11 Feb 2020 21:07:05 +0000 Subject: [PATCH 2/2] Remove stating default behaviour of fill in example Co-Authored-By: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com> --- 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 33c2b3ed137b..190381c75ca0 100644 --- a/examples/color/named_colors.py +++ b/examples/color/named_colors.py @@ -68,7 +68,7 @@ def plot_colortable(colors, title, sort_colors=True, emptycols=0): ax.add_patch( Rectangle(xy=(swatch_start_x, y-9), width=swatch_width, - height=18, fill=True, facecolor=colors[name]) + height=18, facecolor=colors[name]) ) return fig