Search code examples
imagematlabmatlab-figure

Box on and axis coordinates in a Matlab picture


I am trying to construct a picture in Matlab. I want the box of the plot to be included (box on ) and the coordinates of the axis reported up to the limit I set. Consider for example

scatter(-0.5, 0.399, 'c','filled');
box on
axis([-0.504 -0.494 0.397 0.408 ])
legend('A')
xlabel('\gamma_0')
ylabel('\delta_0')
title('N=3') 

Now, you can see that on the vertical axis the last tick at the top is not numerated. I don't understand why. Could you help to fix this?


Solution

  • I think it is only a visualization issue. If you want to make sure your limits are shown you may force the ticks value:

    scatter(-0.5, 0.399, 'c','filled');
    box on
    axis([-0.504 -0.494 0.397 0.408 ])
    
    xticks(linspace(-0.504, -0.494, 11)); % Set the ticks vector as a vector of 11 elements from -0.504 to -0.494
    yticks(linspace(0.397, 0.408, 11));
    
    legend('A')
    xlabel('\gamma_0')
    ylabel('\delta_0')
    title('N=3') 
    

    Image in my matlab

    In your comment you specified you want only three digits format. In format string that is '%1.3f'. You can force also the formatting of your ticks:

    scatter(-0.5, 0.399, 'c','filled');
    box on
    axis([-0.504 -0.494 0.397 0.408 ])
    
    xtickformat('%1.3f');
    ytickformat('%1.3f');
    xticks(linspace(-0.504, -0.494, 11)); 
    yticks(linspace(0.397, 0.408, 11));
    
    legend('A')
    xlabel('\gamma_0')
    ylabel('\delta_0')
    title('N=3') 
    

    this is the result:

    enter image description here