Avoid colorbar resizing image
Show older comments
Hi guys -
How can I prevent an image from being resized when a colorbar is introduced? I am plotting two plots side by side, one with a line plot and one with imagesc. Before the colorbar is added the plots are exactly the same size, which I would prefer, but when I add the colorbar the imagesc plot is resized to be smaller than before. I'd like to avoid this.
Accepted Answer
More Answers (3)
Sindar
on 27 Mar 2019
If you set the position of the colorbar manually, the figure won't be resized. So:
cb=colorbar;
cb.Position = cb.Position + 1e-10; % or + [left, bottom, width, height] to place it where you want
Will auto-place the colorbar, then un-resize the plot.
1 Comment
Shiyu Zhao
on 20 Feb 2021
This helps! Thanks!
Chad Greene
on 2 Mar 2012
This is sort of a clunky solution, but you can force the entire figure to be the size you want by putting this line after plotting:
set(gcf,'position',[100 100 1100 650]) % sets figure size
I believe the 100s above correspond to the position (in pixels) of the lower left corner of the figure on your screen, and 1100 and 650 are the figure width and height, respectively.
3 Comments
Jason
on 2 Mar 2012
Jason
on 2 Mar 2012
Chad Greene
on 2 Mar 2012
It's possible that my line placed your figure somewhere off your screen. Try running your code WITHOUT my line, then in the command line type
get(gcf,'position')
It should return some value like [50 100 500 450] (I'm making up the values). Those are the default values for the position and size of your figure. If you want your figure to be, say, 100 pixels wider, then take those values and type in
set(gcf,'position',[50 100 600 450])
Jason
on 2 Mar 2012
Categories
Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!