I am drawing a graph using the plot() function, but by default it doesn't show the axes.
How do we enable showing the axes at x=0 and y=0 on the graph?
Actually my graph is something like:
And I want a horizontal line corresponding to y=0. How do I get that?
Easiest solution:
plot([0,0],[0.0], xData, yData);
This creates an invisible line between the points [0,0] to [0,0] and since Matlab wants to include these points it will shows the axis.
The poor man's solution is to simply graph the lines x=0 and y=0. You can adjust the thickness and color of the lines to differentiate them from the graph.
Maybe
grid on
will suffice.If you want the axes to appear more like a crosshair, instead of along the edges, try axescenter from the Matlab FEX.
EDIT: just noticed this is already pointed out in the link above by Jitse Nielsen.
@Martijn your order of function calls is slightly off. Try this instead:
By default, plot does show axes, unless you've modified some settings. Try the following