Search code examples
matlabplotmatlab-figure

How to increase number of points in matlab Graph?


I have two arrays x and y. Array x contains values 10,20,30,40,....1000. And array y contains some random value between 0 to 1. I plotted graph in Matlab then on x-axis it is pointing 100, 200, 300... 1000 only. So The analysis in graph seems to be not as expected. If x-axis contains point intervals with some less difference (here 100), then there may be a chance the outcome will be perfect. How to do that?


Solution

  • Matlab shows you x-ticks in a spacing that will be clear enough to read. You can set the spacing in X-axis ticks as you want with xticks (and the same for yticks), if you have Matlab 2016b or later, and with set command for earlier versions. Here is an example:

    x = 10:1000;
    y = rand(1,size(x,2));
    plot(x,y,'o')
    set(gca,'XTick',50:50:1000) % <- set the places where X axis have ticks
    % xticks(50:50:1000) % in version 2016b or later
    

    The result with the example above:

    enter image description here