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

后端 未结 9 1361
再見小時候
再見小時候 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:57

    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.

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

    @Martijn your order of function calls is slightly off. Try this instead:

    x=-3:0.1:3;
    y = x.^3;
    plot(x,y), hold on
    plot([-3 3], [0 0], 'k:')
    hold off
    
    0 讨论(0)
  • 2021-02-13 10:06

    This should work in Matlab:

    set(gca, 'XAxisLocation', 'origin')
    

    Options are: bottom, top, origin.

    For Y.axis:

    YAxisLocation; left, right, origin
    
    0 讨论(0)
提交回复
热议问题