Decimal numbers problem on plotting
3 次查看(过去 30 天)
显示 更早的评论
I am plotting a graph about a parameter that changes according to years on MATLAB. But on the years label, decimal numbers are seen. How can I make them unseen?
0 个评论
回答(1 个)
DGM
2021-5-11
编辑:DGM
2021-5-11
Consider:
% make a simple plot that reproduces the fractional year ticks
x = 2016:0.5:2020
plot(x,x)
% get rid of tick labels for non-integer years
xtl = get(gca,'xticklabel')
mask = cellfun(@(x)mod(str2num(x),1)>eps,xtl);
xtl(mask) = {''}
set(gca,'xticklabel',xtl)
There are probably other ways to do this, but this is what I came up with off the top of my head.
2 个评论
DGM
2021-5-11
You might also be able to get away with something like this:
x = 2016:0.5:2020
plot(x,x)
xt = get(gca,'xtick')
set(gca,'xtick',xt(mod(xt,1)==0))
though it will also remove the half-year tick marks as well
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Labels and Annotations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!