How to use time (in year) as your x axis for plots when your data is in quarters in Matlab?

10 visualizzazioni (ultimi 30 giorni)
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!! :)

Risposte (2)

Walter Roberson
Walter Roberson il 12 Nov 2011
datetick('x', 'yyyy QQ')
  3 Commenti
Walter Roberson
Walter Roberson il 12 Nov 2011
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
Walter Roberson il 12 Nov 2011
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');

Accedi per commentare.


karan
karan il 12 Nov 2011
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 Commenti
karan
karan il 22 Nov 2011
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
Walter Roberson il 22 Nov 2011
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

Accedi per commentare.

Community Treasure Hunt

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

Start Hunting!

Translated by