Why does the colorbar in my figure reposition itself when I print the figure in MATLAB 7.0.1 (R14SP1)?

1 view (last 30 days)
If I create a colorbar and then reposition it as in the following example, the colorbar will return to its original postion when I print or resize the figure.
surf(peaks)
hcb = colorbar;
set(hcb,'units','centimeter','position',[8 1 2 3])

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 2009
This bug has been fixed in Release 14 Service Pack 3 (R14SP3). For previous product releases, read below for any possible workarounds:
We have verified that there is a bug in MATLAB 7.0.1 (R14) in the way that it resizes figures containing a colorbar whose 'Units' property is not set to 'normalized'.
To work around this issue, use normalized units when creating the colorbar. For instance, replace the example above with the following:
hf = figure('units','centimeters');
surf(peaks)
% Convert centimeters to normalized units
figPosCM = get(hf,'Position');
posNormalized = [8./figPosCM(3) 1./figPosCM(4) 2./figPosCM(3) 3./figPosCM(4)];
% Create colorbar in a nondefault location using normalized units
hcb = colorbar('units', 'normalized','position',posNormalized);

More Answers (0)

Products


Release

R14SP1

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!