Python 如何在matplotlib中使用预先制作的热图颜色图?

Python 如何在matplotlib中使用预先制作的热图颜色图?,python,matplotlib,Python,Matplotlib,我想将中的颜色贴图用于matplotlib热贴图 我试着这样做: myHeatMap.imshow(heatMap, extent=ext, cmap=get_cmap(cm.datad["Spectral"])) 然而,Python解释器抱怨 in get_cmap if name in cmap_d: TypeError: unhashable type: 'dict' 使用这些颜色贴图的正确方法是什么?看起来您只是调用了get\u cmap错误。尝试: from pylab i

我想将中的颜色贴图用于matplotlib热贴图

我试着这样做:

myHeatMap.imshow(heatMap, extent=ext, cmap=get_cmap(cm.datad["Spectral"]))
然而,Python解释器抱怨

in get_cmap
if name in cmap_d:
    TypeError: unhashable type: 'dict'

使用这些颜色贴图的正确方法是什么?

看起来您只是调用了
get\u cmap
错误。尝试:

from pylab import imshow, show, get_cmap
from numpy import random

Z = random.random((50,50))   # Test data

imshow(Z, cmap=get_cmap("Spectral"), interpolation='nearest')
show()

命名的颜色贴图是什么? 运行代码:

from pylab import cm
print cm.datad.keys()
提供颜色贴图列表,其中任何一个都可以替换为
“光谱”


使用
matplotlib
打印时,可以使用
cmap=plt.get\u cmap(“颜色映射的名称”)
例如:
plt.pcolormesh(terux,teruy,masked\uheight.data,cmap=plt.get\ucmap('terrain'))

有许多预定义的名称,所有这些名称都已列出

然而,我发现仅仅通过查看颜色条很难想象2d绘图会是什么样子。因此,我创建了一个地形图,其中包含了您可以查看的每个可能的
matplotlib
colormap

['Spectral', 'summer', 'RdBu', 'Set1', 'Set2', 'Set3', 'brg_r', 'Dark2', 'hot', 'PuOr_r', 'afmhot_r', 'terrain_r', 'PuBuGn_r', 'RdPu', 'gist_ncar_r', 'gist_yarg_r', 'Dark2_r', 'YlGnBu', 'RdYlBu', 'hot_r', 'gist_rainbow_r', 'gist_stern', 'gnuplot_r', 'cool_r', 'cool', 'gray', 'copper_r', 'Greens_r', 'GnBu', 'gist_ncar', 'spring_r', 'gist_rainbow', 'RdYlBu_r', 'gist_heat_r', 'OrRd_r', 'bone', 'gist_stern_r', 'RdYlGn', 'Pastel2_r', 'spring', 'terrain', 'YlOrRd_r', 'Set2_r', 'winter_r', 'PuBu', 'RdGy_r', 'spectral', 'flag_r', 'jet_r', 'RdPu_r', 'Purples_r', 'gist_yarg', 'BuGn', 'Paired_r', 'hsv_r', 'bwr', 'YlOrRd', 'Greens', 'PRGn', 'gist_heat', 'spectral_r', 'Paired', 'hsv', 'Oranges_r', 'prism_r', 'Pastel2', 'Pastel1_r', 'Pastel1', 'gray_r', 'PuRd_r', 'Spectral_r', 'gnuplot2_r', 'BuPu', 'YlGnBu_r', 'copper', 'gist_earth_r', 'Set3_r', 'OrRd', 'PuBu_r', 'ocean_r', 'brg', 'gnuplot2', 'jet', 'bone_r', 'gist_earth', 'Oranges', 'RdYlGn_r', 'PiYG', 'YlGn', 'binary_r', 'gist_gray_r', 'Accent', 'BuPu_r', 'gist_gray', 'flag', 'seismic_r', 'RdBu_r', 'BrBG', 'Reds', 'BuGn_r', 'summer_r', 'GnBu_r', 'BrBG_r', 'Reds_r', 'RdGy', 'PuRd', 'Accent_r', 'Blues', 'Greys', 'autumn', 'PRGn_r', 'Greys_r', 'pink', 'binary', 'winter', 'gnuplot', 'pink_r', 'prism', 'YlOrBr', 'rainbow_r', 'rainbow', 'PiYG_r', 'YlGn_r', 'Blues_r', 'YlOrBr_r', 'seismic', 'Purples', 'bwr_r', 'autumn_r', 'ocean', 'Set1_r', 'PuOr', 'PuBuGn', 'afmhot']