Setting alpha color bar in MATLAB R2014b

I have a colorplot (from imagesc) with an alpha map. I would like the color bar to display alpha (note that in the image below the color patterns are the same). I found solutions online, but none of them work in R2014b.

The code is here:

subplot(2,1,1)
A = imagesc(meshgrid(0:10,0:5));
alpha(A,1)
colorbar

subplot(2,1,2)
B = imagesc(meshgrid(0:10,0:5));
alpha(B,.7)
colorbar

      

Same colormap - different alphas.

James

+3


source to share


2 answers


In pre-R2014b MATLAB is colorbar

itself an axis containing an image for which you can set the alpha:

hb = findobj(gcf,'Type','axes','Tag','Colorbar'); 
hi = findobj(hb,'Type','image');
alpha(hi,0.7)

      

Instead gcf

, use the descriptors of individual sub board.



Or store a handle to it when you do it:

hb = colorbar;

      

From R2014b on, the color bar is created using the new graphics handle system, in which the child image no longer needs to be modified. colorbar

is created inside with colorbarHGUsingMATLABClasses

, which is a confusing .p file, so it is not clear how it was created.

0


source


You can add a text box with alpha on top of the color bar. This works for later versions of MATLAB.



cb=colorbar

annotation('textbox',...
    cb.Position,...
    'FitBoxToText','off',...
    'FaceAlpha',0.5,...
    'EdgeColor',[1 1 1],...
    'BackgroundColor',[1 1 1]);

      

0


source







All Articles