How do i make my subplots equal widths with the axes also equal?
40 次查看(过去 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
2014-6-10
编辑:David Wang
2014-6-10
Have you figured out any solution? I'm having exactly the same problem.
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
2014-6-10
Use the xlim() and ylim() functions to set the axes limits to what you want them to be.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Subplots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!