Customizing the tick values and labels along x axis
27 次查看(过去 30 天)
显示 更早的评论
Hi All,
When I plot(1:20, f), the x-axis are shown from 1 to 20. However my real x values are
x =
Columns 1 through 13
30.0000 28.0000 26.0000 24.0000 22.0000 20.0000 18.0000 16.0000 14.0000 12.0000 10.0000 8.0000 6.0000
Columns 14 through 20
4.0000 2.0000 1.0000 0.8000 0.6000 0.4000 0.2000
and I'd like the real x values to show up in the figure. To do so, I used
xticks([x])
and got an error that says
Value must be a numeric vector whose values increase.
Any idea how I can fix this issue?
Thanks in advance
0 个评论
采纳的回答
Star Strider
2021-6-23
编辑:Star Strider
2021-6-23
Try something like this:
x = [30.0000 28.0000 26.0000 24.0000 22.0000 20.0000 18.0000 16.0000 14.0000 12.0000 10.0000 8.0000 6.0000 4.0000 2.0000 1.0000 0.8000 0.6000 0.4000 0.2000];
figure
plot(rand(1,20))
set(gca, 'XTick',1:20, 'XTickLabel',compose('%g',x))
EDIT — (23 Jun 2021 at 22:21)
Since I’m not certain what you’re actually doing, another option is:
x = [30.0000 28.0000 26.0000 24.0000 22.0000 20.0000 18.0000 16.0000 14.0000 12.0000 10.0000 8.0000 6.0000 4.0000 2.0000 1.0000 0.8000 0.6000 0.4000 0.2000];
figure
plot(x, rand(1,20))
set(gca, 'XTick',sort(x), 'XDir','reverse')
.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Annotations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!