Timetable Variable grouped by year and stackedplot
Mostrar comentarios más antiguos
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
Respuesta aceptada
Más respuestas (1)
Cris LaPierre
el 14 de Dic. de 2020
1 voto
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 comentarios
John Barron
el 14 de Dic. de 2020
Cris LaPierre
el 14 de Dic. de 2020
Editada: Cris LaPierre
el 14 de Dic. de 2020
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
el 14 de Dic. de 2020
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
el 14 de Dic. de 2020
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.
Categorías
Más información sobre Discrete Data Plots en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

