1- #issue https://github.com/matplotlib/matplotlib/issues/2164
2-
31import numpy as np
42import matplotlib .pyplot as plt
5- from matplotlib .colors import cnames
3+ from matplotlib import cbook
4+ from matplotlib import colors
65from itertools import chain
76
8- print len (cnames .keys ())
9- n = len (cnames )
7+ n = len (colors .cnames )
108ncols = n / 15
119nrows = 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
1529fig , axes_ = plt .subplots (nrows = nrows , ncols = ncols )
1630axes = list (chain (* axes_ ))
1731
1832for 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