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

Skip to content

Commit 20d21c0

Browse files
committed
sorted by hue, sat, val
1 parent 3a596d3 commit 20d21c0

File tree

1 file changed

+25
-16
lines changed

1 file changed

+25
-16
lines changed

examples/color/named_colors.py

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,44 @@
1-
#issue https://github.com/matplotlib/matplotlib/issues/2164
2-
31
import numpy as np
42
import matplotlib.pyplot as plt
5-
from matplotlib.colors import cnames
3+
from matplotlib import cbook
4+
from matplotlib import colors
65
from itertools import chain
76

8-
print len(cnames.keys())
9-
n = len(cnames)
7+
n = len(colors.cnames)
108
ncols = n / 15
119
nrows = n / ncols
12-
names = cnames.keys()
13-
colors = cnames.values()
10+
11+
names = colors.cnames.keys()
12+
hex_ = colors.cnames.values()
13+
rgb = [colors.hex2color(color) for color in hex_]
14+
hsv = [colors.rgb_to_hsv(color) for color in rgb]
15+
16+
hue = [color[0] for color in hsv]
17+
sat = [color[1] for color in hsv]
18+
val = [color[2] for color in hsv]
19+
20+
ind = np.lexsort((val, sat, hue))
21+
22+
names_ = []
23+
colors_ = []
24+
25+
for i in ind:
26+
names_.append(names[i])
27+
colors_.append(hex_[i])
1428

1529
fig, axes_ = plt.subplots(nrows=nrows, ncols=ncols)
1630
axes = list(chain(*axes_))
1731

1832
for i in range(n):
19-
title = axes[i].set_title(names[i])
33+
title = axes[i].set_title(names_[i])
2034
title.set_size('xx-small')
21-
axes[i].set_axis_bgcolor(colors[i])
35+
axes[i].set_axis_bgcolor(colors_[i])
2236
axes[i].spines['right'].set_visible(False)
2337
axes[i].spines['top'].set_visible(False)
2438
axes[i].spines['bottom'].set_visible(False)
2539
axes[i].spines['left'].set_visible(False)
2640
axes[i].set_xticks([])
2741
axes[i].set_yticks([])
2842

29-
# axes[i].set_label(names[i])
30-
31-
# for axes in list(chain(*axes_)):
32-
# axes.set_axis_off()
33-
34-
# print nrows, ncols, fig, axes
35-
plt.show()
43+
plt.tight_layout()
44+
plt.show()

0 commit comments

Comments
 (0)