|
38 | 38 | sorted_colors = [colors_[i] for i in ind]
|
39 | 39 |
|
40 | 40 | n = len(sorted_colors)
|
41 |
| -ncols = 3 |
| 41 | +ncols = 4 |
42 | 42 | nrows = int(np.ceil(1. * n / ncols))
|
43 | 43 |
|
44 |
| -fig = plt.figure(figsize=(ncols*2.5, nrows*2)) |
| 44 | +X = [(0., 0.08, 0.1), |
| 45 | + (0.33, 0.41, 0.43), |
| 46 | + (0.66, 0.74, 0.76)] |
| 47 | + |
| 48 | + |
| 49 | +fig = plt.figure() |
| 50 | +ax = fig.add_subplot(111) |
| 51 | + |
| 52 | +X, Y = fig.get_dpi() * fig.get_size_inches() |
| 53 | + |
| 54 | +# row height |
| 55 | +h = Y / (nrows + 1) |
| 56 | +# col width |
| 57 | +w = X / ncols |
| 58 | + |
| 59 | + |
45 | 60 | for i, (name, color) in enumerate(sorted_colors):
|
46 |
| - ax = fig.add_subplot(nrows, ncols, i + 1) |
47 |
| - ax.text(0.55, 0.5, name, fontsize=12, |
| 61 | + col = i % ncols |
| 62 | + row = int(i / ncols) |
| 63 | + y = Y - (row * h) - h |
| 64 | + |
| 65 | + xi_text = w * (col + 0.3) |
| 66 | + xi_line = w * (col + 0.05) |
| 67 | + xf_line = w * (col + 0.25) |
| 68 | + |
| 69 | + ax.text(xi_text, y, name, fontsize=(h * 0.8), |
48 | 70 | horizontalalignment='left',
|
49 | 71 | verticalalignment='center')
|
50 | 72 |
|
51 |
| - # Add extra black line a little bit thicker to make |
52 |
| - # clear colors more visible. |
53 |
| - ax.hlines(0.5, 0, 0.5, color='black', linewidth=10) |
54 |
| - ax.hlines(0.5, 0, 0.5, color=color, linewidth=8) |
55 |
| - ax.set_xlim(0, 1) |
56 |
| - ax.set_ylim(0, 1) |
57 |
| - ax.set_axis_off() |
58 |
| - |
59 |
| -fig.subplots_adjust(left=0.01, right=0.99, |
60 |
| - top=0.99, bottom=0.01, |
61 |
| - hspace=1, wspace=0.1) |
| 73 | +# Add extra black line a little bit thicker to make |
| 74 | +# clear colors more visible. |
| 75 | + ax.hlines(y, xi_line, xf_line, color='black', linewidth=(h * 0.7)) |
| 76 | + ax.hlines(y + h * 0.1, xi_line, xf_line, color=color, linewidth=(h * 0.6)) |
| 77 | +ax.set_xlim(0, X) |
| 78 | +ax.set_ylim(0, Y) |
| 79 | +ax.set_axis_off() |
| 80 | + |
| 81 | +fig.subplots_adjust(left=0, right=1, |
| 82 | + top=1, bottom=0, |
| 83 | + hspace=0, wspace=0) |
62 | 84 | plt.show()
|
0 commit comments