Timetable Variable grouped by year and stackedplot
이전 댓글 표시
I have the following unstacked timetable that I would like to plot with the stackedplot function.
The stackedplot should have the Day/Month as the X-Axis and it should be "stacked" or grouped by the year.
Should the grouping be done by some timetable function or should I just loop through the timetable with the required conditions? Thanks!
Datum DailyAvgTemp
__________ ____________
01.01.1956 -6.8
02.01.1956 -3.7
03.01.1956 -4.5
04.01.1956 -5.2
05.01.1956 0
06.01.1956 -3.8
...
05.11.2018 -2
06.11.2018 -2.8
채택된 답변
추가 답변 (1개)
Cris LaPierre
2020년 12월 14일
1 개 추천
For stackedplot to work as you intend, you would have to make each year's data its own variable (column). There is no timetable function for that. Also note that stackedplot has a maximum of 25 variables (1 variable = 1 plot). It looks like you might have 63.
댓글 수: 4
John Barron
2020년 12월 14일
You don't need it, and year(TT.date) can extract it easily enough.
While not ideal if there are 63 years of data, one way to show this in a single plot would be this.
% create a sample dataset
datum = (datetime(1956,1,1):calmonths(1):datetime(1960,12,1))';
avgTemp = randi(100,[length(datum),1]);
TT = timetable(datum,avgTemp)
% Plot grouping by year
h=gscatter(month(TT.datum),TT.avgTemp,year(TT.datum));
set(h,'LineStyle','-');
xticks(1:12);
xticklabels(["Jan" "Feb" "Mar" "Apr" "May" "Jun" "Jul" "Aug" "Sep" "Oct" "Nov" "Dec"]);
legend('Location','eastoutside')
Adam Danz
2020년 12월 14일
If you were set on using a stacked plot, you could break apart your data into 3-5 year segments and show multiple years in each axes.
Cris LaPierre
2020년 12월 14일
Looks like I incorrectly assumed dates were mm-dd-yyyy, which is simpler to solve. If it's dd-mm-yyyy, it gets a little more challenging.
카테고리
도움말 센터 및 File Exchange에서 Discrete Data Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

