|
40 | 40 | 'gist_rainbow', 'rainbow', 'jet', 'nipy_spectral', 'gist_ncar'])] |
41 | 41 |
|
42 | 42 |
|
43 | | -nrows = max(len(cmap_list) for cmap_category, cmap_list in cmaps) |
44 | 43 | gradient = np.linspace(0, 1, 256) |
45 | 44 | gradient = np.vstack((gradient, gradient)) |
46 | 45 |
|
47 | 46 |
|
48 | | -def plot_color_gradients(cmap_category, cmap_list, nrows): |
49 | | - fig, axes = plt.subplots(nrows=nrows) |
50 | | - fig.subplots_adjust(top=0.95, bottom=0.01, left=0.2, right=0.99) |
| 47 | +def plot_color_gradients(cmap_category, cmap_list): |
| 48 | + # Create figure and adjust figure height to number of colormaps |
| 49 | + nrows = len(cmap_list) |
| 50 | + figh = 0.35 + 0.15 + (nrows + (nrows-1)*0.1)*0.22 |
| 51 | + fig, axes = plt.subplots(nrows=nrows, figsize=(6.4, figh)) |
| 52 | + fig.subplots_adjust(top=1-.35/figh, bottom=.15/figh, left=0.2, right=0.99) |
| 53 | + |
51 | 54 | axes[0].set_title(cmap_category + ' colormaps', fontsize=14) |
52 | 55 |
|
53 | 56 | for ax, name in zip(axes, cmap_list): |
54 | 57 | ax.imshow(gradient, aspect='auto', cmap=plt.get_cmap(name)) |
55 | | - pos = ax.get_position().bounds |
56 | | - x_text = pos[0] - 0.01 |
57 | | - y_text = pos[1] + pos[3]/2. |
58 | | - fig.text(x_text, y_text, name, va='center', ha='right', fontsize=10) |
| 58 | + ax.text(-.01, .5, name, va='center', ha='right', fontsize=10, |
| 59 | + transform=ax.transAxes) |
59 | 60 |
|
60 | 61 | # Turn off *all* ticks & spines, not just the ones with colormaps. |
61 | 62 | for ax in axes: |
62 | 63 | ax.set_axis_off() |
63 | 64 |
|
64 | 65 |
|
65 | 66 | for cmap_category, cmap_list in cmaps: |
66 | | - plot_color_gradients(cmap_category, cmap_list, nrows) |
| 67 | + plot_color_gradients(cmap_category, cmap_list) |
67 | 68 |
|
68 | 69 | plt.show() |
69 | 70 |
|
|
0 commit comments