How to change my x axis value
Afficher commentaires plus anciens
Hello. Is it possible for me to change my x axis value? My data is from 1982-2017. I plot and came out like this:

but I want it to be like this:

The x-axis showing the year.
Thank you in advance!
Réponse acceptée
Plus de réponses (1)
WalterWhite
le 14 Jan 2021
1 vote
xticks(1980:5:2020)
5 commentaires
the cyclist
le 14 Jan 2021
I think you mean xticklabels.
WalterWhite
le 14 Jan 2021
i just set the range of the x-axis values between 1980-2020. I didn't label them. I was of the impression that the labels will be generated automatically in that range by matlab
Nurul Ain Basirah Zakaria
le 14 Jan 2021
WalterWhite
le 14 Jan 2021
xticks(1980:5:2020) %try pasing this code under your plot(spi3)
the cyclist
le 14 Jan 2021
Modifié(e) : the cyclist
le 14 Jan 2021
To be clear about what I was saying, if OP has plotted with one variable, like this
rng default
figure
plot(rand(1,9))
they will get the plot

and this plot will not be fixed by adding
xticks(1980:5:2020)
which will create ticks at x-axis positions 1980:5:2020, and the plot will then look like this

because the data are at 1:9, and the ticks are far away to the right at 1980-2020. Instead, they could use
xticklabels(1980:5:2020)
to change the labels of the existing tick marks at 1:9 into 1980:5:2020, yielding

But I think it is fundamentally better to actually plot the date data, as suggested in my solution.
Catégories
En savoir plus sur Time Series Objects dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!