How to set the size of a colorbar in a subplot?

30 views (last 30 days)
I am creating a (1,3) subplot and want to put one colorbar on the right.
I have already used previously suggested answers in order to move it the way I wanted with the 'Position' matrix
The problem is that when changing the size of the figure window, the colorbar doesn't follow these changes as the subplots.
More precisely, the width and the x bottom left keep an acceptable ratio but not the height or the y bottom right
Typically, picture 1 is good (and done manually) and then picture 2 is not so good anymore, just after a few adjustements to the figure window size)
This is the code I am using
colorbar('Position', [0.95 0.25 0.02 0.535])
Would there be a way to fix the length of the color bar to adjust to the size of the subplots at all time ?
Thanks a lot
  2 Comments
dpb
dpb on 28 Oct 2021
Write a callback function tied to the figure's 'SizeChangedFcn' callback.
Alternatively, while I've never actually gone to the trouble to do either, you might investigate the tip provided in the documentation
Tip
As an easy alternative to specifying a SizeChangedFcn callback, you can set the Units property of all the objects you put inside a container to 'normalized'. Doing so makes those components scale proportionally with the container.
dpb
dpb on 29 Oct 2021
You'll probably have more luck in somebody trying to play with your issue if you'll attach a working minimal example to produce a sample figure to work on. It's much simpler to have the starting point already created rather than trying to first create your working conditions.

Sign in to comment.

Answers (0)

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!