4. matplotlib.cm
matplotlib.cm
模块包含了一系列的colormap
,以及相关的函数。它主要有两个函数:matplotlib.cm.get_cmap(name=None, lut=None)
:获取一个colormap
实例。其中:name
:指定了colormap
的名字。如果为None
,则使用rc
配置。如果它已经是colormap
实例,则直接返回该实例。注意:register_cmap
注册的colormap
优先查询lut
:一个整数。如果非None
,则指定了查询表的number of entries
matplotlib.cm.register_cmap(name=None, cmap=None, data=None, lut=None)
:注册一个colormap
。有两种使用方式:register_cmap(name='swirly', cmap=swirly_cmap)
:此时cmap
参数必须是matplotlib.colors.Colormap
实例。name
默认为该Colormap
实例的.name
属性。register_cmap(name='choppy', data=choppydata, lut=128)
:此时这三个参数传递给matplotlib.colors.LinearSegementedColormap
初始化函数。
所有的内置的
name
如下:'Perceptually Uniform Sequential':['viridis', 'inferno', 'plasma', 'magma']
'Sequential':['Blues', 'BuGn', 'BuPu','GnBu', 'Greens', 'Greys', 'Oranges', 'OrRd',
'PuBu', 'PuBuGn', 'PuRd', 'Purples', 'RdPu','Reds', 'YlGn', 'YlGnBu',
'YlOrBr', 'YlOrRd']
'Sequential (2)':['afmhot', 'autumn', 'bone', 'cool','copper', 'gist_heat', 'gray',
'hot','pink', 'spring', 'summer', 'winter']
'Diverging':['BrBG', 'bwr', 'coolwarm', 'PiYG', 'PRGn', 'PuOr',
'RdBu', 'RdGy', 'RdYlBu', 'RdYlGn', 'Spectral','seismic']
'Qualitative':['Accent', 'Dark2', 'Paired', 'Pastel1', 'Pastel2',
'Set1', 'Set2', 'Set3']
'Miscellaneous':['gist_earth', 'terrain', 'ocean', 'gist_stern','brg',
'CMRmap', 'cubehelix','gnuplot', 'gnuplot2',
'gist_ncar','nipy_spectral', 'jet', 'rainbow',
'gist_rainbow', 'hsv', 'flag', 'prism']
你可以使用
cm.get_cmap('winter')
来使用,也可以直接用cm.winter
来使用。