matplotlib 可视化 cmap colormap

分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow

也欢迎大家转载本篇文章。分享知识,造福人民,实现我们中华民族伟大复兴!

                       

<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 ListedColormapcolors = ('lightgreen', 'cyan', 'gray', 'r', 'b')cmp = ListedColormap(colors[:np.unique(y_train)])
   
   
  • 1
  • 2
  • 3
           

给我老师的人工智能教程打call!http://blog.csdn.net/jiangjunshow

这里写图片描述

猜你喜欢

转载自blog.csdn.net/hftytf/article/details/83759742
今日推荐