필터 지우기
필터 지우기

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

조회 수: 14 (최근 30일)
Fox
Fox 2016년 1월 2일
댓글: Fox 2016년 1월 4일
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 ?

채택된 답변

dpb
dpb 2016년 1월 3일
편집: dpb 2016년 1월 3일
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.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by