|
199 | 199 | # First, we'll show the range of each colormap. Note that some seem |
200 | 200 | # to change more "quickly" than others. |
201 | 201 |
|
202 | | -nrows = max(len(cmap_list) for cmap_category, cmap_list in cmaps.items()) |
203 | 202 | gradient = np.linspace(0, 1, 256) |
204 | 203 | gradient = np.vstack((gradient, gradient)) |
205 | 204 |
|
206 | 205 |
|
207 | | -def plot_color_gradients(cmap_category, cmap_list, nrows): |
208 | | - fig, axs = plt.subplots(nrows=nrows) |
209 | | - fig.subplots_adjust(top=0.95, bottom=0.01, left=0.2, right=0.99) |
| 206 | +def plot_color_gradients(cmap_category, cmap_list): |
| 207 | + # Create figure and adjust figure height to number of colormaps |
| 208 | + nrows = len(cmap_list) |
| 209 | + figh = 0.35 + 0.15 + (nrows + (nrows - 1) * 0.1) * 0.22 |
| 210 | + fig, axs = plt.subplots(nrows=nrows + 1, figsize=(6.4, figh)) |
| 211 | + fig.subplots_adjust(top=1 - 0.35 / figh, bottom=0.15 / figh, |
| 212 | + left=0.2, right=0.99) |
210 | 213 | axs[0].set_title(cmap_category + ' colormaps', fontsize=14) |
211 | 214 |
|
212 | 215 | for ax, name in zip(axs, cmap_list): |
213 | 216 | ax.imshow(gradient, aspect='auto', cmap=plt.get_cmap(name)) |
214 | | - pos = list(ax.get_position().bounds) |
215 | | - x_text = pos[0] - 0.01 |
216 | | - y_text = pos[1] + pos[3]/2. |
217 | | - fig.text(x_text, y_text, name, va='center', ha='right', fontsize=10) |
| 217 | + ax.text(-0.01, 0.5, name, va='center', ha='right', fontsize=10, |
| 218 | + transform=ax.transAxes) |
218 | 219 |
|
219 | 220 | # Turn off *all* ticks & spines, not just the ones with colormaps. |
220 | 221 | for ax in axs: |
221 | 222 | ax.set_axis_off() |
222 | 223 |
|
223 | 224 |
|
224 | 225 | for cmap_category, cmap_list in cmaps.items(): |
225 | | - plot_color_gradients(cmap_category, cmap_list, nrows) |
| 226 | + plot_color_gradients(cmap_category, cmap_list) |
226 | 227 |
|
227 | 228 | plt.show() |
228 | 229 |
|
|
0 commit comments