1. 程式人生 > >matplotlib 視覺化 —— cmap(colormap)

matplotlib 視覺化 —— cmap(colormap)

<a href=“http://matplotlib.org/examples/color/colormaps_reference.html”, target="_blank">color example code: colormaps_reference.py — Matplotlib 2.0.0 documentation

由其文件可知,在 colormap 類別上,有如下分類:

  • perceptual uniform sequential colormaps:感知均勻的序列化 colormap
  • sequential colormaps:序列化(連續化)色圖 colormap;
    • gray
      :0-255 級灰度,0:黑色,1:白色,黑底白字;
    • gray_r:翻轉 gray 的顯示,如果 gray 將影象顯示為黑底白字,gray_r 會將其顯示為白底黑字;
    • binary
  • diverging colormaps:兩端發散的色圖 colormaps;
    • seismic
  • qualitative colormaps:量化(離散化)色圖;
  • miscellaneous colormaps:其他色圖;
    • rainbow

1. matplotlib

  • 設定 cmap 的幾種方式:

    plt.imshow(image, cmap=plt.get_cmap('gray_r'))
    plt.imshow(image, cmap='gray_r')
    plt.imshow(image, cmap=plt.cm.binary)
    
    • 1
    • 2
    • 3

2. ListedColormap

class ListedColormap(Colormap):
    """Colormap object generated from a list of colors.
    ...
    """
  • 1
  • 2
  • 3
  • 4
from matplotlib.colors import ListedColormap
colors = ('lightgreen', 'cyan', 'gray', 'r', 'b')
cmp = ListedColormap(colors[:np.unique(y_train)])
  • 1
  • 2
  • 3

再分享一下我老師大神的人工智慧教程吧。零基礎!通俗易懂!風趣幽默!還帶黃段子!希望你也加入到我們人工智慧的隊伍中來!https://www.cnblogs.com/captainbed