How to show x and y axes in a MATLAB graph?

后端 未结 9 1334
再見小時候
再見小時候 2021-02-13 09:27

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

相关标签:
9条回答
  • 2021-02-13 09:41

    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.

    0 讨论(0)
  • 2021-02-13 09:42

    Maybe grid on will suffice.

    0 讨论(0)
  • 2021-02-13 09:50

    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
    
    0 讨论(0)
  • 2021-02-13 09:52

    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.

    0 讨论(0)
  • 2021-02-13 09:54

    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

    0 讨论(0)
  • 2021-02-13 09:56

    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
    
    0 讨论(0)
提交回复
热议问题