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

Skip to content

Commit d38932a

Browse files
committed
three column arrangement
1 parent 7115159 commit d38932a

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed

examples/color/named_colors.py

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,45 +2,49 @@
22
import matplotlib.pyplot as plt
33
from matplotlib import cbook
44
from matplotlib import colors
5-
5+
66
colors_ = colors.cnames.items()
7-
7+
88
#add the single letter colors
99
for name, rgb in colors.ColorConverter.colors.items():
1010
hex_ = colors.rgb2hex(rgb)
1111
colors_.append((name, hex_))
12-
12+
1313
#hex color values
1414
hex_ = [color[1] for color in colors_]
1515
#rgb equivalent
1616
rgb = [colors.hex2color(color) for color in hex_]
1717
#hsv equivalent
1818
hsv = [colors.rgb_to_hsv(color) for color in rgb]
19-
19+
2020
#split the hsv to sort
2121
hue = [color[0] for color in hsv]
2222
sat = [color[1] for color in hsv]
2323
val = [color[2] for color in hsv]
24-
24+
2525
#sort by hue, saturation and value
2626
ind = np.lexsort((val, sat, hue))
2727
sorted_colors = [colors_[i] for i in ind]
28-
28+
2929
n = len(sorted_colors)
30-
ncols = 10
30+
ncols = 3
3131
nrows = int(np.ceil(1. * n / ncols))
32-
33-
fig = plt.figure()
32+
33+
fig = plt.figure(figsize=(ncols*5, nrows*4))
3434
for i, (name, color) in enumerate(sorted_colors):
3535
ax = fig.add_subplot(nrows, ncols, i + 1,
36-
axisbg=color,
3736
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)
4650
plt.show()

0 commit comments

Comments
 (0)