Changing number of dates shown on xaxis

1 次查看(过去 30 天)
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

采纳的回答

dpb
dpb 2015-9-7
编辑:dpb 2015-9-7
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...

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Dates and Time 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by