resize the figure without colorbar in subplot

8 ビュー (過去 30 日間)
hamed amini
hamed amini 2021 年 1 月 26 日
コメント済み: hamed amini 2021 年 1 月 26 日
I'd like to keep similar right edges for the subplots with and without colorbar

採用された回答

Michael Ladegaard
Michael Ladegaard 2021 年 1 月 26 日
You can save the default position of each of your plots or subplots and then reset to those values after creating the color bar. However, if you reset to the default values, the color bar might get pushed outside of the figure frame, so consider using the axes function as shown below.
I hope this helps:
clear
figure(99),clf
ax(1) = axes('Position',[0.1300 0.60 0.65 0.35]) ; % or: ax(1) = subplot(2,1,1) ;
pos{1} = ax(1).Position ; % save default values
x = [-pi:0.1:pi] ;
y = cos(x) ;
plot(x,y)
ax(2) = axes('Position',[ax(1).Position(1) 0.11 ax(1).Position(3) ax(1).Position(4)]) ; % or: ax(2) = subplot(2,1,2) ;
pos{2} = ax(2).Position ; % save default values
membrane % function that plots the MATLAB logo
cb_handle = colorbar ;
% reset axes positions to default values after creating colorbar:
ax(2).Position = pos{2} ; % or: ax(2).Position = ax(1).Position
  1 件のコメント
hamed amini
hamed amini 2021 年 1 月 26 日
Thanks! The key was that the 'position' propoerty changes after adding the colorbar or even changing the xlim. I thought the position was fixed and sreved as a refrence for the plot components.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeColormaps についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by