|
2 | 2 | import matplotlib.pyplot as plt
|
3 | 3 | from matplotlib import cbook
|
4 | 4 | from matplotlib import colors
|
5 |
| - |
| 5 | + |
6 | 6 | colors_ = colors.cnames.items()
|
7 |
| - |
| 7 | + |
8 | 8 | #add the single letter colors
|
9 | 9 | for name, rgb in colors.ColorConverter.colors.items():
|
10 | 10 | hex_ = colors.rgb2hex(rgb)
|
11 | 11 | colors_.append((name, hex_))
|
12 |
| - |
| 12 | + |
13 | 13 | #hex color values
|
14 | 14 | hex_ = [color[1] for color in colors_]
|
15 | 15 | #rgb equivalent
|
16 | 16 | rgb = [colors.hex2color(color) for color in hex_]
|
17 | 17 | #hsv equivalent
|
18 | 18 | hsv = [colors.rgb_to_hsv(color) for color in rgb]
|
19 |
| - |
| 19 | + |
20 | 20 | #split the hsv to sort
|
21 | 21 | hue = [color[0] for color in hsv]
|
22 | 22 | sat = [color[1] for color in hsv]
|
23 | 23 | val = [color[2] for color in hsv]
|
24 |
| - |
| 24 | + |
25 | 25 | #sort by hue, saturation and value
|
26 | 26 | ind = np.lexsort((val, sat, hue))
|
27 | 27 | sorted_colors = [colors_[i] for i in ind]
|
28 |
| - |
| 28 | + |
29 | 29 | n = len(sorted_colors)
|
30 |
| -ncols = 10 |
| 30 | +ncols = 3 |
31 | 31 | nrows = int(np.ceil(1. * n / ncols))
|
32 |
| - |
33 |
| -fig = plt.figure() |
| 32 | + |
| 33 | +fig = plt.figure(figsize=(ncols*5, nrows*4)) |
34 | 34 | for i, (name, color) in enumerate(sorted_colors):
|
35 | 35 | ax = fig.add_subplot(nrows, ncols, i + 1,
|
36 |
| - axisbg=color, |
37 | 36 | xticks=[], yticks=[])
|
38 |
| - title = ax.set_title(name) |
39 |
| - title.set_size('xx-small') |
40 |
| - ax.spines['right'].set_visible(False) |
41 |
| - ax.spines['top'].set_visible(False) |
42 |
| - ax.spines['bottom'].set_visible(False) |
43 |
| - ax.spines['left'].set_visible(False) |
44 |
| - |
45 |
| -plt.tight_layout() |
| 37 | + ax.text(0.55, 0.5, name, fontsize=12, |
| 38 | + horizontalalignment='left', |
| 39 | + verticalalignment='center') |
| 40 | + |
| 41 | + ax.hlines(0.5, 0, 0.5, color='black', linewidth=9) |
| 42 | + ax.hlines(0.5, 0, 0.5, color=color, linewidth=8) |
| 43 | + ax.set_xlim(0, 1) |
| 44 | + ax.set_ylim(0, 1) |
| 45 | + ax.set_axis_off() |
| 46 | + |
| 47 | +fig.subplots_adjust(left=0.01, right=0.99, |
| 48 | + top=0.99, bottom=0.01, |
| 49 | + hspace=1, wspace=0.1) |
46 | 50 | plt.show()
|
0 commit comments