How do i make my subplots equal widths with the axes also equal?

41 ビュー (過去 30 日間)
Grant Dickson
Grant Dickson 2013 年 2 月 28 日
回答済み: Image Analyst 2014 年 6 月 10 日
I have the following code to plot three circular arcs. All three are the same width but different heights. The units on all axes are in meters and to make the plots to scale I have used the axis equal command.
L=16;
x=linspace(-L/2,L/2,100);
H=L/2;
R=(H^2+(L/2)^2)/(2*H);
y=(R^2-x.^2).^(1/2)+H-R;
subplot(311); plot(x,y), axis equal, axis([-L/2 L/2 0 H])
H=L/4;
R=(H^2+(L/2)^2)/(2*H);
y=(R^2-x.^2).^(1/2)+H-R;
subplot(312); plot(x,y), axis equal, axis([-L/2 L/2 0 H])
H=L/8;
R=(H^2+(L/2)^2)/(2*H);
y=(R^2-x.^2).^(1/2)+H-R;
subplot(313); plot(x,y), axis equal, axis([-L/2 L/2 0 H])
Because the arcs are different heights, MATLAB has automatically squashed and stretched them to fit in the window together. I want to make all three plots the same width (and different heights).
  2 件のコメント
David Wang
David Wang 2014 年 6 月 10 日
編集済み: David Wang 2014 年 6 月 10 日
Have you figured out any solution? I'm having exactly the same problem.
Adam Danz
Adam Danz 2014 年 6 月 10 日
Hello Grant,
A while ago I wrote an m-file to automatically adjust the axes of a subplot based on the global max and min values. I just uploaded it so you could take a look at it.
If your plot that includes the subplot is active, all you have to do is call the file 'eqaxsp' (equal axis subplots).
If you have subplot handles (recommended), you could enter them. Example sp(1) = subplot(311) sp(2) = subplot(312) sp(3) = subplot(313) etc...
then call eqaxsp(sp)
If you'd like to control the axes limits, eqaxsp(sp, [xmin xmax ymin ymax]);
There are examples in the help-section of the code which I've just uploaded here

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

回答 (1 件)

Image Analyst
Image Analyst 2014 年 6 月 10 日
Use the xlim() and ylim() functions to set the axes limits to what you want them to be.

カテゴリ

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