1
- #issue https://github.com/matplotlib/matplotlib/issues/2164
2
-
3
1
import numpy as np
4
2
import matplotlib .pyplot as plt
5
- from matplotlib .colors import cnames
3
+ from matplotlib import cbook
4
+ from matplotlib import colors
6
5
from itertools import chain
7
6
8
- print len (cnames .keys ())
9
- n = len (cnames )
7
+ n = len (colors .cnames )
10
8
ncols = n / 15
11
9
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 ])
14
28
15
29
fig , axes_ = plt .subplots (nrows = nrows , ncols = ncols )
16
30
axes = list (chain (* axes_ ))
17
31
18
32
for i in range (n ):
19
- title = axes [i ].set_title (names [i ])
33
+ title = axes [i ].set_title (names_ [i ])
20
34
title .set_size ('xx-small' )
21
- axes [i ].set_axis_bgcolor (colors [i ])
35
+ axes [i ].set_axis_bgcolor (colors_ [i ])
22
36
axes [i ].spines ['right' ].set_visible (False )
23
37
axes [i ].spines ['top' ].set_visible (False )
24
38
axes [i ].spines ['bottom' ].set_visible (False )
25
39
axes [i ].spines ['left' ].set_visible (False )
26
40
axes [i ].set_xticks ([])
27
41
axes [i ].set_yticks ([])
28
42
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