Plot several time series data stacked in one graph
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Vu Minh
am 5 Mär. 2023
Kommentiert: Star Strider
am 6 Mär. 2023
Dear all,
I have the dynamic area data for 7 years from 2016 to 2022 as attached in the excel file. I want to plot 7 line of data with x axis is the date from 01/01 to 31/12 (year excluded) and y axis is the area value but I do not know how to plot with only day and month. Then I want to add a legend to distinguish 7 years. Can you help me with this please!
0 Kommentare
Akzeptierte Antwort
Star Strider
am 5 Mär. 2023
Bearbeitet: Star Strider
am 5 Mär. 2023
Try this —
T1 = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1314900/Data.xlsx')
VN = T1.Properties.VariableNames;
DateMtx = T1{:,1:2:end};
for k = 1:size(DateMtx,2)
[y,m,d] = ymd(DateMtx(:,k));
MDdt(:,k) = datetime(1,m,d);
end
figure
hold on
for k = 1:size(MDdt,2)
plot(MDdt(:,k), T1{:,2*k}, 'DisplayName',strrep(VN{2*k},'_','\_'))
end
grid
xtickformat('dd/MM')
legend('Location','best')
xlabel('dd/MM')
ylabel('Area')
EDIT — (5 Mar 2023 at 17:38)
Corrected typographical error (specifically so that xticklabel correctly matches xtickformat). Code unchanged.
.
2 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Dates and Time finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!