How do i make my subplots equal widths with the axes also equal?
40 views (last 30 days)
Show older comments
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 Comments
David Wang
on 10 Jun 2014
Edited: David Wang
on 10 Jun 2014
Have you figured out any solution? I'm having exactly the same problem.
Adam Danz
on 10 Jun 2014
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
Answers (1)
Image Analyst
on 10 Jun 2014
Use the xlim() and ylim() functions to set the axes limits to what you want them to be.
0 Comments
See Also
Categories
Find more on Subplots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!