1
$\begingroup$

By default, when I plot a graph, the axis seems to be at the lower limit

x=linspace(-10,10,20)
y=4*x+2
plot(x,y)

http://is.gd/f9zOkl

How can I have the axis when x=0 & y=0, for example below

http://www.regentsprep.org/Regents/math/algtrig/ATP8b/inversegraph.gif

UPDATE

If its not possible to use real "axis", I am thinking of plotting the graphs x=0 & y=0 for the y & x axis respectively, how might I do that?

Then isit possble to show where they intersect? like in format like (x, y) eg. (0, 2)

$\endgroup$
0
$\begingroup$

It seems that this is not (easily) possible. For your information: I found the following links:

$\endgroup$
  • $\begingroup$ Thanks, I am trying to plot graphs of x=0 and y=0 to simulate the y & x axis, how might I do that? See updated post/question $\endgroup$ – Jiew Meng Aug 28 '11 at 6:16
1
$\begingroup$

try this:

set (gca, "xaxislocation", "zero");

set (gca, "yaxislocation", "zero");

It works only for Octave, not Matlab. Would be interesting also to know how do this with matlab.

$\endgroup$
  • $\begingroup$ I have seen this command in many of the sites but surprisingly it doesn't work in my GNU Octave $\endgroup$ – Debashish Sep 2 '18 at 18:14
0
$\begingroup$

After creating your plot, you could try this which draws lines:

% Keep the current graph
hold;
% Draw X axis
plot([-6 6], [0 0], 'k-'); % Draws a line between x=(-6 to 6) and y=(0 to 0)
% Draw Y axis
plot([0 0], [-5 5], 'k-'); % Draws a line between x=(0 to 0) and y=(-5 to 5)

In plot([-6 6], [0 0], 'k-'); replace -6 with the lower limit for x and 6 with the upper limit.

In plot([0 0], [-5 5], 'k-'); replace -5 with the lower limit for y and 5 with the upper limit.

$\endgroup$

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.