Help with plot axis

13 次查看(过去 30 天)
I have a piece of code that goes through a loop 1000 times determining the values of x and y. I then plot these coordinates.
I want the x and y axis to be the same so I tried axis equal however I obtained a graph with the axises as so. Can anyone explain why the x and y axis aren't equal? The x axis ranges from -300 to 300 and the y axis from 0 to 450.

采纳的回答

Star Strider
Star Strider 2017-3-7
The axis equal call uses the same length for the data units along each axis. It does not affect the range of values. If you want to change those, use the axis call as:
axis([xmin xmax ymin ymax])
You can also combine that call with an axis equal call, so one does not cancel or override the other.
  2 个评论
Sinead Mc Kinney
Sinead Mc Kinney 2017-3-7
Thanks for your response. However i'm not sure i am making use of this correctly. I want the x and y axis both to span the same range of values. See image attached - i would like the x axis to range from 0 to 450 as the y axis does. I have tried the following however i receive an error.
ymin = min(coords(:,2));
ymax = max(coords(:,2));
rangeOfyAxis=ymax-ymin;
xmin = -floor(rangeOfyAxis/2);
xmax = floor(rangeOfyAxis/2);
axis([xmin xmax,ymin ymax])
Error using matlab.graphics.axis.Axes/set Value must be a 1x2 vector of numeric type in which the second element is larger than the first and may be Inf
Error in axis>LocSetLimits (line 269) set(ax,...
Error in axis (line 98) LocSetLimits(ax(j),cur_arg,names);
Error in simulateLightningTenToThePowerOfThree (line 51) axis([xmin xmax,ymin ymax])
Star Strider
Star Strider 2017-3-7
My pleasure.
‘I would like the x axis to range from 0 to 450 as the y axis does.’
Use the ‘ymin’ and ‘ymax’ values for both in your axis call:
axis([ymin ymax ymin ymax])
That should do what you want.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Annotations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by