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 th
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.
Maybe grid on
will suffice.
By default, plot does show axes, unless you've modified some settings. Try the following
hold on; % make sure no new plot window is created on every plot command
axes(); % produce plot window with axes
plot(% whatever your plot command is);
plot([0 10], [0 0], 'k-'); % plot the horizontal line
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.
Inspired by @Luisa's answer, I made a function, axes0
x = linspace(-2,2,101);
plot(x,2*x.^3-3*x+1);
axes0
You can follow the link above to download the function and get more details on usage
I know this is coming a bit late, but a colleague of mine figured something out:
figure, plot ((1:10),cos(rand(1,10))-0.75,'*-')
hold on
plot ((1:10),zeros(1,10),'k+-')
text([1:10]-0.09,ones(1,10).*-0.015,[{'0' '1' '2' '3' '4' '5' '6' '7' '8' '9'}])
set(gca,'XTick',[], 'XColor',[1 1 1])
box off