python - Making image white space transparent, overlay onto imshow() -
i have plot of spatial data display imshow().
i need able overlay crystal lattice produced data. have png file of lattice loads black , white image.the parts of image want overlay black lines lattice , not see white background between lines.
i'm thinking need set alphas each background ( white ) pixel transparent (0 ? ).
i'm new don't know how ask question.
edit:
import matplotlib.pyplot plt import numpy np lattice = plt.imread('path') im = plt.imshow(data[0,:,:],vmin=v_min,vmax=v_max,extent=(0,32,0,32),interpolation='nearest',cmap='jet') im2 = plt.imshow(lattice,extent=(0,32,0,32),cmap='gray') #thinking of making mask white background mask = np.ma.masked_where( lattice < 1,lattice ) #confusion here b/c tho theimage gray scale in8, 0-255, numpy array lattice 0-1.0 floats...?
with out data, can't test this, like
import matplotlib.pyplot plt import numpy np import copy my_cmap = copy.copy(plt.cm.get_cmap('gray')) # copy of gray color map my_cmap.set_bad(alpha=0) # set how colormap handles 'bad' values lattice = plt.imread('path') im = plt.imshow(data[0,:,:],vmin=v_min,vmax=v_max,extent=(0,32,0,32),interpolation='nearest',cmap='jet') lattice[lattice< thresh] = np.nan # insert 'bad' values lattice (the white) im2 = plt.imshow(lattice,extent=(0,32,0,32),cmap=my_cmap)
alternately, can hand imshow
nxmx4 np.array
of rbga values, way don't have muck color map
im2 = np.zeros(lattice.shape + (4,)) im2[:, :, 3] = lattice # assuming lattice bool array imshow(im2)
Comments
Post a Comment