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

55 次查看(过去 30 天)
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.

标签

Community Treasure Hunt

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

Start Hunting!

Translated by