Reputation: 2299
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?
Upvotes: 3
Views: 60
Reputation: 41
You can set the ticks manually using the function set
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')
yTickDiff = diff(get(gca,'YTick'));
set(gca,'YTick',[0.397:yTickDiff(1):0.408])
Upvotes: 2
Reputation: 60443
What is happening looks to be a floating-point rounding issue. Octave curiously does exactly the same thing.
>> axis([-0.504 -0.494 0.397 0.408 ])
>> t=get(gca,'ytick')
t =
0.39600 0.39800 0.40000 0.40200 0.40400 0.40600 0.40800
>> l=get(gca,'ylim')
l =
0.39700 0.40800
>> t(end)-l(end)
ans =
5.5511e-17
So there is a tick mark at 0.408, but the location of the tick mark is still just above the axis limit, so it is not shown.
You can explicitly set the tick locations, as Matteo suggests, or explicitly set the axis limits:
ylim([0.397,t(end)])
Note that the trick here is to use the exact location of the tick mark, t(end)
, rather than the constant 0.408
, which is a different value.
Upvotes: 2
Reputation: 2956
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')
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:
Upvotes: 2