Plot year as major ticks and months as minor ticks

12 次查看(过去 30 天)
I haves several years worth of time series data and I want to plot the major ticks as years, with labels and mior ticks as months with no labels. I can see how to plot major and minor ticks, but not with date/time data.
Thanks.

采纳的回答

dpb
dpb 2021-6-16
If your time data are evenly-spaced and at monthly intervals,
hAx=gca; hX=hAx.XAxis; % get handle to X datetime ruler object
xt=hX.TickValues; % get the tick values; presuming are yearly by default
isYr=(mod(1:numel(xt),12)==1); % the indices to the year tick locations
hX.MinorTickValues=xt(~isYr); % write the monthly dates as minor ticks
If your data aren't regular or don't begin precisely on the first of the year, then use create a regular monthly timeseries between the XLIM values of the axis and write those similarly.
It does seem as though the datetimeRuler could/should have a 'monthly' and various other named intervals to use to specify the common labeling that one would want similar to the options in 'retime'
  1 个评论
Chris McGibbon
Chris McGibbon 2021-6-18
The data are neither evenly spaced, nor at monthly intervals, but I'll try making the monthly time series segments.
Thanks for the help.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Calendar 的更多信息

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by