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 日
Cris LaPierre
2020 年 12 月 14 日
編集済み: Cris LaPierre
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!

