How to change the x axis labels of a plot so that they only show integer values
218 次查看(过去 30 天)
显示 更早的评论
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/248425/image.png)
Thanks!
3 个评论
回答(2 个)
Walter Roberson
2019-11-15
ax = gca;
ax.Xticks = unique( round(ax.XTicks) );
2 个评论
Walter Roberson
2020-3-12
编辑:Walter Roberson
2020-3-12
ax is a variable assigned the result of gca . gca is a function that returns a handle to the current axes. So ax will be assigned a handle to the current axes.
ax = gca;
ax.XTick = unique( round(ax.XTick) );
SHC
2020-3-12
curtick = get(gca, 'xTick');
xticks(unique(round(curtick)));
2 个评论
Walter Roberson
2020-3-12
Note: this requires R2016b or later. For earlier releases, especially before R2015b, it would look like,
curtick = get(gca, 'XTick');
set(gca, 'XTick', unique(round(curtick)))
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Axis Labels 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!