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

Skip to content

Convert named_colors example to use Rectangle #16467

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 11, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions examples/color/named_colors.py
Original file line number Diff line number Diff line change
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