Plot several time series data stacked in one graph
    6 views (last 30 days)
  
       Show older comments
    
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 Comments
Accepted Answer
  Star Strider
      
      
 on 5 Mar 2023
        
      Edited: Star Strider
      
      
 on 5 Mar 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 Comments
More Answers (0)
See Also
Categories
				Find more on Dates and Time in Help Center and File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

