Setting alpha of colorbar in MATLAB R2014b

☆樱花仙子☆ 提交于 2020-01-14 14:07:43

问题


I have a colorplot (from imagesc) with an alpha map. I'd like the colorbar to reflect the alpha (notice that in the image below the colormaps are the same). I found solutions online but none seem to work in R2014b.

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

James


回答1:


You could add a textbox with alpha on top of the colorbar. 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]);



回答2:


In pre-R2014b MATLAB, the colorbar is itself an axis containing an image for which you can set alpha:

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

Instead of gcf, use the handles of the individual subplots.

Or save its handle when you make it:

hb = colorbar;

From R2014b on, the colorbar is creating using the new handle graphics system, where there is no longer a child image to modify. The colorbar is created internally with colorbarHGUsingMATLABClasses, which is an obfuscated .p file, so it's no clear how it's constructed.



来源:https://stackoverflow.com/questions/27240862/setting-alpha-of-colorbar-in-matlab-r2014b

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!