How to define a transparent element in a color palette

I would like to define a transparent color in a color map, how to do it?

I need this so that I have several layers in my axes (created by both imagesc and plot ). I know that I could just use imagesc first and then plot , but I want to draw lines behind the non-zero values โ€‹โ€‹of the imagesc .

To color the zeros of white, I use

 jet = colormap('jet'); jet(1:2,:) = 1; colormap(jet); 

Now I want to make white transparent.

+6
source share
1 answer

colormap does not have a fourth element for alpha, it is only RGB, so the way I do it is to mask the desired level of transparency - binary or gray scale - and then apply this to the image. To do this, you need to save the image descriptor

 % make random image im = rand(100,100); % make example alphamask alphamask = im<0.3; % store handle hnd = imagesc(im); % apply mask set(hnd, 'AlphaData', alphamask); 
+9
source

Source: https://habr.com/ru/post/986371/


All Articles