本文整理汇总了Python中matplotlib.cm.ScalarMappable.get_cmap方法的典型用法代码示例。如果您正苦于以下问题:Python ScalarMappable.get_cmap方法的具体用法?Python ScalarMappable.get_cmap怎么用?Python ScalarMappable.get_cmap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.cm.ScalarMappable
的用法示例。
在下文中一共展示了ScalarMappable.get_cmap方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: cmap_discretize
# 需要导入模块: from matplotlib.cm import ScalarMappable [as 别名]
# 或者: from matplotlib.cm.ScalarMappable import get_cmap [as 别名]
def cmap_discretize(cmap, N):
"""Return a discrete colormap from the continuous colormap cmap.
cmap: colormap instance, eg. cm.jet.
N: number of colors.
Example
x = resize(arange(100), (5,100))
djet = cmap_discretize(cm.jet, 5)
imshow(x, cmap=djet)
"""
if type(cmap) == str:
cmap = ScalarMappable.get_cmap(cmap)
colors_i = np.concatenate((np.linspace(0, 1., N), (0.,0.,0.,0.)))
colors_rgba = cmap(colors_i)
indices = np.linspace(0, 1., N+1)
cdict = {}
for ki,key in enumerate(('red','green','blue')):
cdict[key] = [(indices[i], colors_rgba[i-1,ki], colors_rgba[i,ki])\
for i in xrange(N+1)]
# Return colormap object.
return LinearSegmentedColormap(cmap.name + "_%d"%N, cdict, 1024)