Customizing the tick values and labels along x axis
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Susan
am 23 Jun. 2021
Kommentiert: Star Strider
am 23 Jun. 2021
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 Kommentare
Akzeptierte Antwort
Star Strider
am 23 Jun. 2021
Bearbeitet: Star Strider
am 23 Jun. 2021
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')
.
2 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Axis Labels finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!