|
35 | 35 | 'terrain', 'ocean', 'gist_earth', 'cubehelix', 'rainbow'
|
36 | 36 | )
|
37 | 37 |
|
38 |
| -for cmap in cmaps: |
39 |
| - n = 512 |
| 38 | +for name in cmaps: |
| 39 | + # The maximum number of segments in a cmap is 256, and for anything smaller, |
| 40 | + # the cmap will map as a suitably discrete set of colours. |
| 41 | + Z = np.linspace(0, 1, 256).reshape(1, 256) |
40 | 42 |
|
41 |
| - if cmap in ['tab10']: n = 10 |
42 |
| - if cmap in ['tab20', 'tab20b', 'tab20c']: n = 20 |
43 |
| - if cmap in ['Pastel1', 'Set1']: n = 9 |
44 |
| - if cmap in ['Pastel2', 'Accent', 'Dark2', 'Set2']: n = 8 |
45 |
| - if cmap in ['Set3']: n = 12 |
46 |
| - if cmap in ['Greys']: n = 11 |
47 |
| - Z = np.linspace(0, 1, n).reshape(1, n) |
48 |
| - |
49 |
| - ax.imshow(Z, extent=[xmin, xmax, ymin, ymax], cmap=plt.get_cmap(cmap)) |
| 43 | + ax.imshow(Z, extent=[xmin, xmax, ymin, ymax], cmap=name) |
50 | 44 | ax.set_xlim(xmin, xmax), ax.set_xticks([])
|
51 | 45 | ax.set_ylim(ymin, ymax), ax.set_yticks([])
|
52 | 46 |
|
53 |
| - """ |
54 |
| - if cmap == "tab10": |
55 |
| - x = np.linspace(xmin, xmax, 11, endpoint=True) + 0.5*(xmax-xmin)/11 |
56 |
| - for i in range(10): |
57 |
| - ax.text(x[i], (ymin+ymax)/2, "C%d"%i, color="white", zorder=10, |
58 |
| - family = "Source Pro Serif", size=10, ha="center", va="center") |
59 |
| -
|
60 |
| - if cmap == "Greys": |
61 |
| - x = np.linspace(xmin, xmax, 12, endpoint=True) + 0.5*(xmax-xmin)/12 |
62 |
| - for i in range(11): |
63 |
| - color = "%.1f"%(i/10) |
64 |
| - text = "%.1f"%(1-i/10) |
65 |
| - ax.text(x[i], (ymin+ymax)/2, text, color=color, zorder=10, |
66 |
| - family = "Source Pro Serif", size=10, ha="center", va="center") |
67 |
| - """ |
68 |
| - |
69 |
| - fig.savefig(ROOT_DIR / f"figures/colormap-{cmap}.pdf") |
| 47 | + fig.savefig(ROOT_DIR / f"figures/colormap-{name}.pdf") |
70 | 48 | ax.clear()
|
0 commit comments