2016-09-07 106 views
-1

我有代碼,給定一個規範化的數組,給出一個rgba數組,使用預定義的顏色映射 - jet在下面的例子中。在Python中使用自定義顏色映射到rgba數組的單值數組

import numpy as np 
from matplotlib import cm 

#arr_orig assumed to be normalized, real array. 
arr_color = np.uint8(cm.jet(arr_orig) * 255) 

我還定義了一個自定義的RGB色彩表,my_colormap,基於代碼http://matplotlib.org/examples/pylab_examples/custom_cmap.html,那我給使用

cm.register_cmap(name = 'custom_colormap', cmap = my_colormap) 

毫不奇怪,不過,我現在不能代替我原來的名字與

arr_color = np.uint8(cm.custom_colormap(arr_orig) * 255) 

代碼當我嘗試,我得到了以下錯誤:

AttributeError: 'module' object has no attribute 'custom_colormap' 

的是一些等同於

arr_color = np.uint8(cm.custom_colormap(arr_orig) * 255) 

,我可以使用,使用此我命名了一個自定義顏色映射一個新的陣列碼?

感謝您的任何幫助。

回答

0

以下工作:

arr_color = cm.ScalarMappable(cmap = custom_colormap).to_rgba(arr_orig, bytes = True)