Plot year as major ticks and months as minor ticks

4 visualizaciones (últimos 30 días)
Chris McGibbon
Chris McGibbon el 16 de Jun. de 2021
Comentada: Chris McGibbon el 18 de Jun. de 2021
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.

Respuesta aceptada

dpb
dpb el 16 de Jun. de 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'
  1 comentario
Chris McGibbon
Chris McGibbon el 18 de Jun. de 2021
The data are neither evenly spaced, nor at monthly intervals, but I'll try making the monthly time series segments.
Thanks for the help.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Calendar en Help Center y File Exchange.

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by