How to use time (in year) as your x axis for plots when your data is in quarters in Matlab?
조회 수: 10 (최근 30일)
이전 댓글 표시
Hello everyone,
I am working on time series data, and have been trying to change my x axis to show number of years or to show not all the quarters. My data is in quarters, starting from 1997, ending in 2010. However, when I try plotting my figures, all quarters are shown, and I have't been able to eliminate any quarters. Showing all quarters on the plot makes it really congested looking, despite using xtick_rotate.
Questions: 1. Is it possible to show say just Q1 1997, Q1 2002, Q1 2007, etc?
2. Is it possible to show say 1997, 1998, 1999, 2000? which means I want to show the year instead of quarters, for my quarterly data?
Many thanks!! :)
댓글 수: 0
답변 (2개)
Walter Roberson
2011년 11월 12일
datetick('x', 'yyyy QQ')
댓글 수: 3
Walter Roberson
2011년 11월 12일
You can use
datetick('x','yyyy')
to show just the year.
Beyond that, you should be investigating setting the XTick property of the axis.
Walter Roberson
2011년 11월 12일
years = 1997:2010
numyears = length(years);
jan1s = zeros(numyears,1);
quarters = zeros(4,numyears);
for Yearno = 1:numyears
thisyear = years(Yearno);
jan1s(Yearno) = datenum([thisyear 1 1]);
quarters(1,Yearno) = jan1s(Yearno);
quarters(2,Yearno) = datenum([thisyear 4 1]);
quarters(3,Yearno) = datenum([thisyear 7 1]);
quarters(4,Yearno) = datenum([thisyear 10 1]);
end
plot(quarters(:),F01);
set(gca,'XTick', jan1s);
datetick('x', 'yyyy');
karan
2011년 11월 12일
Since you havent given the exact possibility ..here is an example of how you would show am/pm in ur plot for every two hours
two_hour = 2/24;
set(gca,'XTick',[two_hour:two_hour:1]); set(gca,'XTickLabel',{'2AM','4AM','6AM','8AM','10AM','12PM','2PM','4PM','6PM','8PM','10PM','12AM'}); set(gca,'XMinorTick','On');
try your case similarly and it will work...the ideology is the same.. i hope this helps
댓글 수: 3
karan
2011년 11월 22일
yes i think you need to do it separately for the subplots ...you can try to have lesser points in order to accommodate the text supporting the ticks...and have minor ticks showing yearly increment ....this will not congest your axis.
Another opinion is to forget about the whole year format ...try using Y97, Y99 or simply 97, 99, 01
If you like my answers and suggestions please accept this answer...cheers!!!
Walter Roberson
2011년 11월 22일
If all the subplots are based on the same time reference, then you can calculate the locations of all of the ticks ahead of time, and then you only need to
set(gca,'XTick', jan1s);
datetick('x', 'yyyy');
for each subplot
참고 항목
카테고리
Help Center 및 File Exchange에서 Axis Labels에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!