Colormap参考

Matplotlib附带的色彩映射参考。

通过将 _r 附加到名称(例如,viridis_r),可以获得每个这些颜色映射的反转版本。

请参阅在Matplotlib中选择Colormaps以深入讨论色彩映射,包括colorblind-friendlyliness。

  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. cmaps = [('Perceptually Uniform Sequential', [
  4. 'viridis', 'plasma', 'inferno', 'magma', 'cividis']),
  5. ('Sequential', [
  6. 'Greys', 'Purples', 'Blues', 'Greens', 'Oranges', 'Reds',
  7. 'YlOrBr', 'YlOrRd', 'OrRd', 'PuRd', 'RdPu', 'BuPu',
  8. 'GnBu', 'PuBu', 'YlGnBu', 'PuBuGn', 'BuGn', 'YlGn']),
  9. ('Sequential (2)', [
  10. 'binary', 'gist_yarg', 'gist_gray', 'gray', 'bone', 'pink',
  11. 'spring', 'summer', 'autumn', 'winter', 'cool', 'Wistia',
  12. 'hot', 'afmhot', 'gist_heat', 'copper']),
  13. ('Diverging', [
  14. 'PiYG', 'PRGn', 'BrBG', 'PuOr', 'RdGy', 'RdBu',
  15. 'RdYlBu', 'RdYlGn', 'Spectral', 'coolwarm', 'bwr', 'seismic']),
  16. ('Cyclic', ['twilight', 'twilight_shifted', 'hsv']),
  17. ('Qualitative', [
  18. 'Pastel1', 'Pastel2', 'Paired', 'Accent',
  19. 'Dark2', 'Set1', 'Set2', 'Set3',
  20. 'tab10', 'tab20', 'tab20b', 'tab20c']),
  21. ('Miscellaneous', [
  22. 'flag', 'prism', 'ocean', 'gist_earth', 'terrain', 'gist_stern',
  23. 'gnuplot', 'gnuplot2', 'CMRmap', 'cubehelix', 'brg',
  24. 'gist_rainbow', 'rainbow', 'jet', 'nipy_spectral', 'gist_ncar'])]
  25. gradient = np.linspace(0, 1, 256)
  26. gradient = np.vstack((gradient, gradient))
  27. def plot_color_gradients(cmap_category, cmap_list):
  28. # Create figure and adjust figure height to number of colormaps
  29. nrows = len(cmap_list)
  30. figh = 0.35 + 0.15 + (nrows + (nrows-1)*0.1)*0.22
  31. fig, axes = plt.subplots(nrows=nrows, figsize=(6.4, figh))
  32. fig.subplots_adjust(top=1-.35/figh, bottom=.15/figh, left=0.2, right=0.99)
  33. axes[0].set_title(cmap_category + ' colormaps', fontsize=14)
  34. for ax, name in zip(axes, cmap_list):
  35. ax.imshow(gradient, aspect='auto', cmap=plt.get_cmap(name))
  36. ax.text(-.01, .5, name, va='center', ha='right', fontsize=10,
  37. transform=ax.transAxes)
  38. # Turn off *all* ticks & spines, not just the ones with colormaps.
  39. for ax in axes:
  40. ax.set_axis_off()
  41. for cmap_category, cmap_list in cmaps:
  42. plot_color_gradients(cmap_category, cmap_list)
  43. plt.show()

Colormap参考示例

Colormap参考示例2

Colormap参考示例3

Colormap参考示例4

Colormap参考示例5

Colormap参考示例6

Colormap参考示例7

参考

此示例中显示了以下函数,方法,类和模块的使用:

  1. import matplotlib
  2. matplotlib.colors
  3. matplotlib.axes.Axes.imshow
  4. matplotlib.figure.Figure.text
  5. matplotlib.axes.Axes.set_axis_off

下载这个示例