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.
0 个评论
采纳的回答
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'
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Calendar 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!