|
| 1 | +""" |
| 2 | +================== |
| 3 | +Colormap reference |
| 4 | +================== |
| 5 | +
|
| 6 | +Reference for colormaps included with Matplotlib. |
| 7 | +
|
| 8 | +A reversed version of each of these colormaps is available by appending |
| 9 | +``_r`` to the name, e.g., ``viridis_r``. |
| 10 | +
|
| 11 | +See :doc:`/tutorials/colors/colormaps` for an in-depth discussion about |
| 12 | +colormaps, including colorblind-friendliness. |
| 13 | +""" |
| 14 | + |
| 15 | +import numpy as np |
| 16 | +import matplotlib.pyplot as plt |
| 17 | + |
| 18 | + |
| 19 | +cmaps = [('Perceptually Uniform Sequential', [ |
| 20 | + 'viridis', 'plasma', 'inferno', 'magma', 'cividis']), |
| 21 | + ('Sequential', [ |
| 22 | + 'Greys', 'Purples', 'Blues', 'Greens', 'Oranges', 'Reds', |
| 23 | + 'YlOrBr', 'YlOrRd', 'OrRd', 'PuRd', 'RdPu', 'BuPu', |
| 24 | + 'GnBu', 'PuBu', 'YlGnBu', 'PuBuGn', 'BuGn', 'YlGn']), |
| 25 | + ('Sequential (2)', [ |
| 26 | + 'binary', 'gist_yarg', 'gist_gray', 'gray', 'bone', 'pink', |
| 27 | + 'spring', 'summer', 'autumn', 'winter', 'cool', 'Wistia', |
| 28 | + 'hot', 'afmhot', 'gist_heat', 'copper']), |
| 29 | + ('Diverging', [ |
| 30 | + 'PiYG', 'PRGn', 'BrBG', 'PuOr', 'RdGy', 'RdBu', |
| 31 | + 'RdYlBu', 'RdYlGn', 'Spectral', 'coolwarm', 'bwr', 'seismic']), |
| 32 | + ('Qualitative', [ |
| 33 | + 'Pastel1', 'Pastel2', 'Paired', 'Accent', |
| 34 | + 'Dark2', 'Set1', 'Set2', 'Set3', |
| 35 | + 'tab10', 'tab20', 'tab20b', 'tab20c']), |
| 36 | + ('Miscellaneous', [ |
| 37 | + 'flag', 'prism', 'ocean', 'gist_earth', 'terrain', 'gist_stern', |
| 38 | + 'gnuplot', 'gnuplot2', 'CMRmap', 'cubehelix', 'brg', 'hsv', |
| 39 | + 'gist_rainbow', 'rainbow', 'jet', 'nipy_spectral', 'gist_ncar'])] |
| 40 | + |
| 41 | + |
| 42 | +nrows = max(len(cmap_list) for cmap_category, cmap_list in cmaps) |
| 43 | +gradient = np.linspace(0, 1, 256) |
| 44 | +gradient = np.vstack((gradient, gradient)) |
| 45 | + |
| 46 | + |
| 47 | +def plot_color_gradients(cmap_category, cmap_list, nrows): |
| 48 | + fig, axes = plt.subplots(nrows=nrows) |
| 49 | + fig.subplots_adjust(top=0.95, bottom=0.01, left=0.2, right=0.99) |
| 50 | + axes[0].set_title(cmap_category + ' colormaps', fontsize=14) |
| 51 | + |
| 52 | + for ax, name in zip(axes, cmap_list): |
| 53 | + ax.imshow(gradient, aspect='auto', cmap=plt.get_cmap(name)) |
| 54 | + pos = list(ax.get_position().bounds) |
| 55 | + x_text = pos[0] - 0.01 |
| 56 | + y_text = pos[1] + pos[3]/2. |
| 57 | + fig.text(x_text, y_text, name, va='center', ha='right', fontsize=10) |
| 58 | + |
| 59 | + # Turn off *all* ticks & spines, not just the ones with colormaps. |
| 60 | + for ax in axes: |
| 61 | + ax.set_axis_off() |
| 62 | + |
| 63 | + |
| 64 | +for cmap_category, cmap_list in cmaps: |
| 65 | + plot_color_gradients(cmap_category, cmap_list, nrows) |
| 66 | + |
| 67 | +plt.show() |
0 commit comments