Plot several time series data stacked in one graph
6 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Star Strider
2023-3-5
编辑:Star Strider
2023-3-5
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.
.
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!