How can I set the width of a COLORBAR in a figure in MATLAB 7.0 (R14)?
106 views (last 30 days)
Show older comments
MathWorks Support Team
on 27 Jun 2009
Commented: Kevin Gleason
on 27 Sep 2016
I create a figure by typing the following at the MATLAB command prompt:
pcolor(peaks);
c=colorbar;
Now I try to set the width of the colorbar as:
x=get(c,'Position');
x(3)=0.03;
set(c,'Position',x)
However, this results in the colorbar in the middle of the figure window.
Accepted Answer
MathWorks Support Team
on 27 Jun 2009
The ability to manually set the width of a colorbar without changing its position is unavailable in MATLAB.
To workaround this issue, type the following:
pcolor(peaks);
c=colorbar;
x1=get(gca,'position');
x=get(c,'Position');
x(3)=0.03;
set(c,'Position',x)
set(gca,'position',x1)
1 Comment
Kevin Gleason
on 27 Sep 2016
You will need to manage the various axes of the figure. Then, "colorbar" can take an axes as argument.
ax1 = subplot(2,1,1);
ax2 = subplot(2,1,2);
pcolor(ax1, peaks);
pcolor(ax2,-peaks);
c1 = colorbar(ax1);
c2 = colorbar(ax2);
x1 = get(ax1, 'position'); % get axes position
cw1= get(c1, 'Position'); % Colorbar Width for c1
% Set position of axes and
From there the modifications and set command from the original answer should work.
More Answers (0)
See Also
Categories
Find more on Subplots in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!