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

40 visualizaciones (últimos 30 días)
Grant Dickson
Grant Dickson el 28 de Feb. de 2013
Respondida: Image Analyst el 10 de Jun. de 2014
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 comentarios
David Wang
David Wang el 10 de Jun. de 2014
Editada: David Wang el 10 de Jun. de 2014
Have you figured out any solution? I'm having exactly the same problem.
Adam Danz
Adam Danz el 10 de Jun. de 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

Iniciar sesión para comentar.

Respuestas (1)

Image Analyst
Image Analyst el 10 de Jun. de 2014
Use the xlim() and ylim() functions to set the axes limits to what you want them to be.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by