python - Getting an RGBA array from a matplotlib image -


i using imshow plot array custom colormap , boundarynorm. however, going automated script , want save image produced imshow without axes. wasn't sure imshow best way since going running in background. there alternative can set colormap , boundarynorm , produce rgba array can give imsave? or left hacking image imshow produce , saving that?

you can use as_rgba_str image data image. here's example:

import numpy np import matplotlib.pyplot plt  x = np.linspace(0, 2, 1000) x, y = np.meshgrid(x, x) data = np.sin((x-2)**3 + y**4)  im = plt.imshow(data)  x = im.make_image() h, w, d = x.as_rgba_str() n = np.fromstring(d, dtype=np.uint8).reshape(h, w, 4)  plt.figure() plt.imshow(n[:,:,0], cmap="gray", origin='lower')  plt.show() 

the original image: enter image description here

the r channel rgba data (note blue sections black since these have no red in them): enter image description here


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -