Effacer les filtres
Effacer les filtres

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

14 vues (au cours des 30 derniers jours)
Fox
Fox le 2 Jan 2016
Commenté : Fox le 4 Jan 2016
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 ?

Réponse acceptée

dpb
dpb le 3 Jan 2016
Modifié(e) : dpb le 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.

Plus de réponses (0)

Catégories

En savoir plus sur Line Plots dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by