| 51 | + 'GnBu', 'PuBu', 'YlGnBu', 'PuBuGn', 'BuGn', 'YlGn']), |
| 52 | + ('Sequential (2)', [ |
| 53 | + 'binary', 'gist_yarg', 'gist_gray', 'gray', 'bone', 'pink', |
| 54 | + 'spring', 'summer', 'autumn', 'winter', 'cool', 'Wistia', |
| 55 | + 'hot', 'afmhot', 'gist_heat', 'copper']), |
| 56 | + ('Diverging', [ |
| 57 | + 'PiYG', 'PRGn', 'BrBG', 'PuOr', 'RdGy', 'RdBu', |
| 58 | + 'RdYlBu', 'RdYlGn', 'Spectral', 'coolwarm', 'bwr', 'seismic']), |
| 59 | + ('Qualitative', [ |
| 60 | + 'Pastel1', 'Pastel2', 'Paired', 'Accent', |
| 61 | + 'Dark2', 'Set1', 'Set2', 'Set3', |
| 62 | + 'tab10', 'tab20', 'tab20b', 'tab20c']), |
| 63 | + ('Miscellaneous', [ |
| 64 | + 'flag', 'prism', 'ocean', 'gist_earth', 'terrain', 'gist_stern', |
| 65 | + 'gnuplot', 'gnuplot2', 'CMRmap', 'cubehelix', 'brg', 'hsv', |
| 66 | + 'gist_rainbow', 'rainbow', 'jet', 'nipy_spectral', 'gist_ncar'])] |
| 67 | + |
| 68 | + |
| 69 | +nrows = max(len(cmap_list) for cmap_category, cmap_list in cmaps) |
| 70 | +gradient = np.linspace(0, 1, 256) |
| 71 | +gradient = np.vstack((gradient, gradient)) |
| 72 | + |
| 73 | + |
| 74 | +def plot_color_gradients(cmap_category, cmap_list, nrows): |
| 75 | + fig, axes = plt.subplots(nrows=nrows) |
| 76 | + fig.subplots_adjust(top=0.95, bottom=0.01, left=0.2, right=0.99) |
| 77 | + axes[0].set_title(cmap_category + ' colormaps', fontsize=14) |
| 78 | + |
| 79 | + for ax, name in zip(axes, cmap_list): |
| 80 | + ax.imshow(gradient, aspect='auto', cmap=plt.get_cmap(name)) |
| 81 | + pos = list(ax.get_position().bounds) |
| 82 | + x_text = pos[0] - 0.01 |
| 83 | + y_text = pos[1] + pos[3]/2. |
| 84 | + fig.text(x_text, y_text, name, va='center', ha='right', fontsize=10) |
| 85 | + |
| 86 | + # Turn off *all* ticks & spines, not just the ones with colormaps. |
| 87 | + for ax in axes: |
| 88 | + ax.set_axis_off() |
| 89 | + |
| 90 | + |
| 91 | +for cmap_category, cmap_list in cmaps: |
| 92 | + plot_color_gradients(cmap_category, cmap_list, nrows) |
| 93 | + |
| 94 | +plt.show() |
0 commit comments