Pregunta

How can I make the vertical axes of two plots equal?

For example:

a = [1 2 3; 21 1 3; 4 2 3; 4 5 6]

After plotting plot(a(1, :)) I get the following figure:
enter image description here

I have done some simple operations:

[U E V] = svd(a);
figure(2);
plot(U(1,:))

And get another figure: enter image description here

How do I make the y-axis limits of both plots equal? Is it with the axes equal command?

UPDATE:
I've used the following commands:

figure (1)
ylim([0 3])
plot(a(1,:))
figure (2);
ylim([0 3])
plot(U(1,:))

But get the same result...

¿Fue útil?

Solución

You can use ylim to force limits on the y-axis. For example:

figure(1)
%// Some plotting...
ylim([0 3])

figure(2)
%// Some more plotting
ylim([0 3])

This ensures that the y-axis is limited to the range [0, 3] in both plots. You can do the same for the limits of the x-axis with the command xlim.

Also note that if you want to set the limits for both axes at once, instead of using xlim and ylim (two commands), you can use axis (one command).

Otros consejos

you can use the ylim or xlim functions.

You can clone the limits of one plot to another plot in this fashion:

h1 = figure;
% do first plot...

h2 = figure;
%do second plot...

% set first figure as active
figure(h1); 

%get limits properties of the axes that are drawn in Figure 1
xL = get(gca, 'XLim');
yL = get(gca, 'YLim');

%switch to second figure and set it as active
figure(h2);

%set axis limit properties of Figure 2 to be the same as in Figure 1
set(gca, 'XLim', xL);
set(gca, 'YLim', yL);
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top