Single-valued array to rgba array using custom color map in Python
<p>I have code that, given a normalized array, gives an rgba array using a predefined colormap - <code>jet</code> in the example below.</p>

<pre><code>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)
</code></pre>

<p>I have also defined a custom rgb colormap, <code>my_colormap</code>, based on code in <a href="http://matplotlib.org/examples/pylab_examples/custom_cmap.html" rel="nofollow">http://matplotlib.org/examples/pylab_examples/custom_cmap.html</a>, and that I gave a name using</p>

<pre><code>cm.register_cmap(name = 'custom_colormap', cmap = my_colormap)
</code></pre>

<p>Unsurprisingly, though, I can't now replace my original code with</p>

<pre><code>arr_color = np.uint8(cm.custom_colormap(arr_orig) * 255)
</code></pre>

<p>When I try this, I get the following error:</p>

<pre><code>AttributeError: 'module' object has no attribute 'custom_colormap'
</code></pre>

<p>What is some code equivalent to</p>

<pre><code>arr_color = np.uint8(cm.custom_colormap(arr_orig) * 255)
</code></pre>

<p>that I can use to make a new array using a custom colormap that I have named?</p>

<p>Thanks for any help.</p>

<p>The following worked:</p>

<pre><code>arr_color = cm.ScalarMappable(cmap = custom_colormap).to_rgba(arr_orig, bytes = True)
</code></pre>

python matplotlib colors colormap