MATLAB: Are some colorbars very thin when using the COLORBAR function in a figure containing multiple subplots in MATLAB 7.0 (R14)

colorbarMATLABnarrowr14subplotwidth

I have created a figure that contains multiple subplots. Each subplot has an associated colorbar. When I execute the following commands:
for n =1:4
subplot(2,2,n)
imagesc(10^n * rand(10))
colorbar
end
I find some of the colorbars are narrower than others.

Best Answer

This bug has been fixed in Release 14 Service Pack 3 (R14SP3). For previous product releases, read below for any possible workarounds:
There is a bug in MATLAB 7.0 (R14) in the way that colorbars are created. The problem occurs when the labels for the colorbar contain large values. Since a colorbar is constrained to occupy a certain width, having large label values results in making the colorbar itself narrower.
To work around this issue, you can change the Position property of the colorbars to make them wider. Note that this solution will not work well when resizing the figure, and you may also need to change the Position of the corresponding sublpot axes. In this case, it may be better to manually create the axes instead of using SUBPLOT, as follows :
figure;
ax(1) = axes('Units','normalized',...
'Position',[.075, .075, .3, .35]);
ax(2) = axes('Units','normalized',...
'Position',[.525, .075, .3, .35]);
ax(3) = axes('Units','normalized',...
'Position',[.075, .575, .3, .35]);
ax(4) = axes('Units','normalized',...
'Position',[.525, .575, .3, .35]);
for n =1:4
imagesc(10^n * rand(10),'Parent',ax(n))
c = colorbar('peer',ax(n));
set(c,'Units','normalized');
pC = get(c,'Position');
pAx = get(ax(n),'Position');
set(c,'Position',[pAx(1)+pAx(3)+.075, pC(2), .05, pC(4)])
end