how to put two different units on my axis

I have a plot with equal axis but i need the x-axes to have twice the unit as the y. 1:2
how do i do that??
Dorrit

2 commentaires

Andrew Newell
Andrew Newell le 12 Mai 2011
Do you mean that you want (for example) the X axes to be from 0 to 2 and the Y axes from 0 to 1?
Or do you mean that you want X and Y to be both from 0 to 1 but have twice as many tick marks on the X axis?
Dorrit
Dorrit le 12 Mai 2011
I mean: if 1cm = one unit on the x-axe then 1cm= two unit on the y-axe.

Connectez-vous pour commenter.

 Réponse acceptée

Kelly Kearney
Kelly Kearney le 12 Mai 2011
Do you mean you want the length of the axes to be the same, but with a 2:1 ratio? Try adjusting the aspect ratio:
x = 0:0.1:1;
y = 2*x;
plot(x,y);
set(gca, 'dataaspectratio', [1 2 1]);

4 commentaires

Dorrit
Dorrit le 12 Mai 2011
If I understand you correkt, it's the last line I shal put in my codes?
this one:
set(gca, 'dataaspectratio', [1 2 1]);
will that give me 2 on the y-axe everytime i have 1 on the x-axe?
Andrew Newell
Andrew Newell le 12 Mai 2011
Yes. You can also use
daspect([1 2 1])
(see http://www.mathworks.com/help/techdoc/ref/daspect.html).
Dorrit
Dorrit le 12 Mai 2011
I think, I can make this work. Thank you.
Dorrit
Dorrit le 12 Mai 2011
Hi, Andrew.
I have tryed daspect, but could only make it work in a 3d plot and not in the 2d plot i'm making not.
I used daspect for my 3d-sphere that you help me with:-)

Connectez-vous pour commenter.

Plus de réponses (1)

Walter Roberson
Walter Roberson le 12 Mai 2011

0 votes

Possibly set() XMinorTick 'on' for the axes would be sufficient ?
If not, then set() the XTick to the tick locations you want. (Note: if you do that, then if you zoom or pan then you will want to use the appropriate callback in those modes to create new XTick according to what is visible.)

Catégories

En savoir plus sur Vector Fields dans Centre d'aide et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by