Subplots with equal "nice" y-axes -- is there a function?

45 ビュー (過去 30 日間)
Douglas Anderson
Douglas Anderson 2012 年 3 月 13 日
コメント済み: David Bennetts 2020 年 6 月 7 日
Hello,
I thought I had seen a function somewhere that would modify subplots so that each of the plots would have the same scale (i.e., ylim) and all of them fit nicely. Kind of like "auto" for the subplot with the highest amplitude applied to all of the subplots.
Is there such a function, or option for an existing function?
Thanks

採用された回答

Tom
Tom 2012 年 3 月 13 日
Once you've finished creating all the subplots (and you have the handles), you can set all of them at once by using :
set(AX_handles,'YLim',[A B])
Where AX_handles is a vector of axes handles, one for each subplot- for example:
for n=1:10
AX(n) = subplot(5,2,n)
end
A and B are your lower and upper limits. Finding the overall max will vary a bit depending on how your data is structed but it shouldn't be too hard.

その他の回答 (4 件)

Jan
Jan 2012 年 3 月 13 日
allYLim = get(AxesHandle, {'YLim'});
allYLim = cat(2, allYLim{:});
set(AxesHandle, 'YLim', [min(allYLim), max(allYLim)]);
The curly braces around 'YLim' in the get command are needed, if AxesHandle is a scalar.

Brett Davenport
Brett Davenport 2018 年 4 月 8 日
編集済み: Brett Davenport 2018 年 4 月 8 日
subplot(1,2,1);plot(t,x);
y1=ylim %gets current limits
subplot(1,2,2);plot(t2,x2);
ylim(y1) %sets limits to that of first subplot

Jorge MARTINEZ
Jorge MARTINEZ 2016 年 9 月 16 日
what about "linkaxes" function?
  2 件のコメント
Brett Davenport
Brett Davenport 2018 年 4 月 8 日
Perfect
David Bennetts
David Bennetts 2020 年 6 月 7 日
Worked perfectly for me too. I had to add it add the end of the script after all of the subplot calls.

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


Jorge MARTINEZ
Jorge MARTINEZ 2016 年 9 月 16 日
anyways, Jan, your solution works like a charm... as usual ;)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by