Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c91d7ef

Browse files
Convert named_colors example to use Rectangle (#16467)
* 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. * Remove stating default behaviour of fill in example Co-Authored-By: Tim Hoffmann <[email protected]> Co-authored-by: Tim Hoffmann <[email protected]>
1 parent f585f9e commit c91d7ef

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

examples/color/named_colors.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* the :doc:`/gallery/color/color_demo`.
1515
"""
1616

17+
from matplotlib.patches import Rectangle
1718
import matplotlib.pyplot as plt
1819
import matplotlib.colors as mcolors
1920

@@ -59,15 +60,16 @@ def plot_colortable(colors, title, sort_colors=True, emptycols=0):
5960
y = row * cell_height
6061

6162
swatch_start_x = cell_width * col
62-
swatch_end_x = cell_width * col + swatch_width
6363
text_pos_x = cell_width * col + swatch_width + 7
6464

6565
ax.text(text_pos_x, y, name, fontsize=14,
6666
horizontalalignment='left',
6767
verticalalignment='center')
6868

69-
ax.hlines(y, swatch_start_x, swatch_end_x,
70-
color=colors[name], linewidth=18)
69+
ax.add_patch(
70+
Rectangle(xy=(swatch_start_x, y-9), width=swatch_width,
71+
height=18, facecolor=colors[name])
72+
)
7173

7274
return fig
7375

@@ -103,4 +105,4 @@ def plot_colortable(colors, title, sort_colors=True, emptycols=0):
103105
matplotlib.figure.Figure.get_size_inches
104106
matplotlib.figure.Figure.subplots_adjust
105107
matplotlib.axes.Axes.text
106-
matplotlib.axes.Axes.hlines
108+
matplotlib.patches.Rectangle

0 commit comments

Comments
 (0)