Plot year as major ticks and months as minor ticks
12 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
dpb
on 16 Jun 2021
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'
More Answers (0)
See Also
Categories
Find more on Calendar in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!