How can I create a plot with quaterly dates on the x-axis ?

15 views (last 30 days)
Hi I have quaterly data from 1973.Q1-2013.Q4. I want to plot this with the quaterly time frame on the x-axis. How can I do this ?

Accepted Answer

dpb
dpb on 3 Jan 2016
Edited: dpb on 3 Jan 2016
dn=datenum(1973,1+[0:3:12*(2013-1973)].',1); % make a sample time vector
[datestr(dn(1)) '<->' datestr(dn(end))] % show what it spans
ans =
01-Jan-1973<->01-Jan-2013
plot(dn,randi(1000,size(dn))) % plot some dummy date over the range
datetick('x','QQ-YYYY') % format axes as time
xlim([dn(1) dn(end)]) % fit axes to range of actual data
You can adjust tick marks and format as desired; somewhat of a problem as the labels take up quite a lot of room but as demonstrated, the x-axis is plotted in date number range of floating point values and then transformed to display time by datetick
With the introduction of the new date/time data type, there's an overloaded plot function that handles that class of time inputs natively; I don't have the release so check the doc's...works generally the same way as the new class is also fundamentally a date number with just more resolution and builtin methods.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!