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개)
참고 항목
카테고리
				Help Center 및 File Exchange에서 Dates and Time에 대해 자세히 알아보기
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


