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 中查找有关 Dates and Time 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

