This question is in continuation of the solution provided by tcaswell (answer #2) for my question: Is there a way to convert pyplot.imshow() object to numpy array?
Consider the following python code:
import pylab
import numpy as np
a = np.array( ( 30, 129 ) , dtype = np.float32 )
b = np.array( ( 30, 129 ) , dtype = np.int32 )
my_cm = pylab.cm.get_cmap('jet')
a_mapped_data = my_cm( a )
b_mapped_data = my_cm( b )
I am using a small array to save space, but this is what is seen even when large arrays are used.
The results:
>>> a
array([ 30., 129.], dtype=float32)
>>> b
array([ 30, 129])
>>> a_mapped_data
array([[ 0.5, 0. , 0. , 1. ],
[ 0.5, 0. , 0. , 1. ]])
>>> b_mapped_data
array([[ 0. , 0. , 1. , 1. ],
[ 0.5028463 , 1. , 0.46489564, 1. ]])
I don't seem to understand the behavior here. Even though the values are same, cm.get_map()
instance is producing different results for numpy.int32
and numpy.float32
data types. Is there something wrong with the code above? Please help out with this. I need to plot 2D arrays of type numpy.float.
I am using python 2.7.3 32bit on Windows7 x64 Home Basic