Changing number of dates shown on xaxis

1 visualización (últimos 30 días)
Locks
Locks el 7 de Sept. de 2015
Editada: dpb el 7 de Sept. de 2015
Hi, I have a plot with time series data of roughly 2 years. When I plot the series, I insert datetick('x','mmmyyyy'); to Format the numerical data. The issue is that I only get displayed two ticks (Jan 2000 and Jan 2010) however I would like to see a tick for each 5 year period for example. The documentation of datetick was not really helpful for this, is there an easy way to define how many ticks including the date gets displayed? thx

Respuesta aceptada

dpb
dpb el 7 de Sept. de 2015
Editada: dpb el 7 de Sept. de 2015
I had presumed the '2' was intended as '20' but had to go to lunch so Star beat my example :) But, the following that had prepared excepting for a typo should resolve the question raised in the follow up--
dn=datenum([1993:2016],1,1).'; % a set of datenums over some 20+ yr
y=rand(size(dn)); % and some dummy data to go along...
plot(dn,y)
yr=datevec([dn(1) dn(end)]); yr=yr(:,1) % get the actual year range
dt=datenum([yr(1)-mod(yr(1),5):5:yr(end)],1,1); % years modulo 5
set(gca,'xtick',dt) % and set the tick marks at those dates
xlim([dn(1) dn(end)]) % now set x limits to range of x dates
datetick('x','mmmmyyyy','keeplimits','keepticks') %to date display
NB: 'keeplimits','keepticks' will prevent the automagic prettifier from futzing around with the values you've asked for. The full month may turn out to be too long for as many ticks as you've asked for; the 'mmmyyyy' format may work better, but you'll have to judge how it looks...
  1 comentario
Locks
Locks el 7 de Sept. de 2015
perfect, excatly what I needed, thanks a lot both of you!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Dates and Time en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by