Matlab set the properties of colorbar
1. Set the colormap of the colorbar
% use the colormap provided by Matlab
colormap(jet); %jet, parula, hsv, hot, etc.
%use a custom colormap
load('RGB_Vincent.mat');
rgbvincent = flipud(RGBVincent);
colormap(rgbvincent);
You can generate or download some custom colormaps beyond the colormaps provided by Matlab in the following online sources.
2. Use colormap for the 1-D line or point plots
% use a colormap
jet = colormap(jet);
line_number = 20;
for ii = 1:line_number
xx = linspace(0,2*pi,100);
yy = sin(xx-pi*(ii-1)/(line_number-1));
plot(xx,yy,'color',jet(floor(ii*256/line_number),:),'linewidth',1.5);
hold on;
end
xlabel('x');
ylabel('sin(x+\phi)');
axis([0,2*pi,-1,1]);
colormap(jet);
c = colorbar;
ax = gca;
axpos = ax.Position;
c.Position(1) = 0.92;
c.Position(3) = 0.5*c.Position(3);
c.Title.String = '\phi (rad)';
set(c,'YTick',[0,1]);
set(c,'YTickLabel',{'0','\pi'});
3. Set the properties of the colorbar
3.1 set the width and position
c = colorbar;
ax = gca;
ax.Position(3) = 0.78; %change the width-to-height ration of the figure inside the windows
axpos = ax.Position;
c.Position(1) = 0.9; % change the position of the colorbar
c.Position(3) = 0.3*c.Position(3); %change the width of the colorbar
3.2 set the value range, label, and ticks
caxis([0,1]);
c.Title.String = 'deg'; % c.Label.String = 'deg'; set label on the right
c.TickLength = 0.005;
set(c,'tickdir','out');
set(c,'YTick',[0,0.5,1]);
set(c,'YTickLabel',{'0','3','6'});