How do I add monthly labels to my time series plot?

조회 수: 5 (최근 30일)
Eloïse
Eloïse 2023년 1월 24일
답변: dpb 2023년 1월 25일
I have data points between 1 and 9862, respresenting each day from 1990 to 2017. I have extracted the first 5 years of data and want to add monthly labels on the x-axis e.g. Oct1990 Nov1990 ..... Sep1995.
  댓글 수: 2
dpb
dpb 2023년 1월 24일
9862/365.25
ans = 27.0007
Is only 27 years, while the difference between 2017 and 1970 is 47 or a 46 year span.
Hence the times cannot be daily.
Easiest would be to define what the time data point really are and use a @doc:datetime vector for the independent variable and plot against it instead. Then you get date labels "for free", the format for which you can set as desired.
Eloïse
Eloïse 2023년 1월 25일
thanks i meant 1990, i'll try that

댓글을 달려면 로그인하십시오.

답변 (1개)

dpb
dpb 2023년 1월 25일
Ah! Typos are the bane of programming! :)
Then
t=datetime(1990,1,1):datetime(2016,12,31); % datetime vector
is5=isbetween(t,t(1),t(1)+years(5)); % logical to get 5 years from beginning
plot(t(is5),randn(sum(is5),1)) % use your dependent variable indexed, too, of course
There's not enough space to label monthly unless you compress the formatting string and/or rotate the labels, but you get time labels automagically with the datetime axis.

카테고리

Help CenterFile Exchange에서 Descriptive Statistics에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by