|
14 | 14 | * the :doc:`/gallery/color/color_demo`.
|
15 | 15 | """
|
16 | 16 |
|
| 17 | +from matplotlib.patches import Rectangle |
17 | 18 | import matplotlib.pyplot as plt
|
18 | 19 | import matplotlib.colors as mcolors
|
19 | 20 |
|
@@ -59,15 +60,16 @@ def plot_colortable(colors, title, sort_colors=True, emptycols=0):
|
59 | 60 | y = row * cell_height
|
60 | 61 |
|
61 | 62 | swatch_start_x = cell_width * col
|
62 |
| - swatch_end_x = cell_width * col + swatch_width |
63 | 63 | text_pos_x = cell_width * col + swatch_width + 7
|
64 | 64 |
|
65 | 65 | ax.text(text_pos_x, y, name, fontsize=14,
|
66 | 66 | horizontalalignment='left',
|
67 | 67 | verticalalignment='center')
|
68 | 68 |
|
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 | + ) |
71 | 73 |
|
72 | 74 | return fig
|
73 | 75 |
|
@@ -103,4 +105,4 @@ def plot_colortable(colors, title, sort_colors=True, emptycols=0):
|
103 | 105 | matplotlib.figure.Figure.get_size_inches
|
104 | 106 | matplotlib.figure.Figure.subplots_adjust
|
105 | 107 | matplotlib.axes.Axes.text
|
106 |
| -matplotlib.axes.Axes.hlines |
| 108 | +matplotlib.patches.Rectangle |
0 commit comments