Skip to content

Commit

Permalink
Convert named_colors example to use Rectangle (#16467)
Browse files Browse the repository at this point in the history
* 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 <2836374+timhoffm@users.noreply.github.com>

Co-authored-by: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com>
  • Loading branch information
asongtoruin and timhoffm committed Feb 11, 2020
1 parent f585f9e commit c91d7ef
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions examples/color/named_colors.py
Expand Up @@ -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

Expand Down Expand Up @@ -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, facecolor=colors[name])
)

return fig

Expand Down Expand Up @@ -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

0 comments on commit c91d7ef

Please sign in to comment.