MATLAB: How to create a colorbar with a white border

barcolorMATLAB

I would like to plot a colorbar in the bottom-right corner of an image. I can do this using the following code:
load clown;
image(X)
colorbar('Location','South','Position',[0.55 0.17 0.3 0.05])
However, the colorbar's labels are obscured by the image. How can I create a white border around the colorbar?

Best Answer

To create a white border around the colorbar, you will need to create an empty AXES object behind the colorbar:
%%Load and plot image data
load clown;
image(X);
%%Define borders for white patch and colorbar
position0=[0.5 0.17 0.4 0.10];
position1=[0.55 0.17 0.3 0.05];
%%Create white patch using an AXES object
% Remove tick labels to end up with an empty rectangle
ha=axes('position', position0)
set(ha,'XTick',[])
set(ha,'XTickLabel',[])
set(ha,'YTick',[])
set(ha,'YTickLabel',[])
% Create a colorbar inside the white patch
hc=colorbar('Location','South','Position',position1)