Quite a busy one-liner, but here it is:
- First ensure your NumPy array,
myarray
, is normalised with the max value at1.0
. - Apply the colormap directly to
myarray
. - Rescale to the
0-255
range. - Convert to integers, using
np.uint8()
. - Use
Image.fromarray()
.
And you’re done:
from PIL import Image
from matplotlib import cm
im = Image.fromarray(np.uint8(cm.gist_earth(myarray)*255))
with plt.savefig()
:
with im.save()
: