Hi everybody
So I made a plot with four subplots (2x2). Now I would like to insert one (big) colorbar on the right Hand side of the four plots without changing the size of any of the plots. Somehow I only manage to make a bar for one subplot...
Cheers Ronny

 採用された回答

Star Strider
Star Strider 2014 年 8 月 2 日

3 投票

I assume you’ve already discovered the colorbar function. See Axis Properties for a description of the properties you can set. The location property applies only to colorbars and legends, not to axes.

4 件のコメント

Ronny
Ronny 2014 年 8 月 2 日
編集済み: Ronny 2014 年 8 月 2 日
Yeah I know. However if I set the colorbar like this it's always in respective to the first of the subplots. What I want is one big colorbar on the right side of all the fore plots...
Star Strider
Star Strider 2014 年 8 月 2 日
See if this does what you want:
x = linspace(0,10,1000);
y = [sin(x); sin(2*x); sin(3*x); sin(4*x)];
figure(1)
for k1 = 1:4
subplot(2,2,k1)
plot(x,y(k1,:))
grid on
end
hp4 = get(subplot(2,2,4),'Position')
colorbar('Position', [hp4(1)+hp4(3)+0.01 hp4(2) 0.1 hp4(2)+hp4(3)*2.1])
You may have to experiment a bit to get it to work exactly as you want with your plot, but it works with this one. The 2.1 factor is a slight fudge, since various combinations of the 'Position' values for subplot(2,2,2) and subplot(2,2,4) didn’t work satisfactorily for me.
Shan  Chu
Shan Chu 2020 年 2 月 13 日
Please help.
Thanks
冠中 王
冠中 王 2022 年 4 月 6 日
For matlab 2019b or after, Create tiled chart layout - MATLAB tiledlayout (mathworks.com) also works and it is easier.

サインインしてコメントする。

その他の回答 (2 件)

Ronny
Ronny 2014 年 8 月 3 日

1 投票

Thanks that works

1 件のコメント

Star Strider
Star Strider 2014 年 8 月 3 日
My pleasure!
You can adjust its left edge position by increasing or decreasing the 0.01 in the first element of the 'Position' vector, and its width by adjusting the third element of the vector.

サインインしてコメントする。

Emmanouil Barmpounakis
Emmanouil Barmpounakis 2017 年 4 月 25 日

1 投票

I came up with the Star Strider's solution but by using the Edit plot function. I found it easier to do it manually, rather than changing the 'Position' vector.tor.

カテゴリ

質問済み:

2014 年 8 月 2 日

コメント済み:

2022 年 4 月 6 日

Community Treasure Hunt

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

Start Hunting!

Translated by