Different legends for multiple graphs
    조회 수: 5 (최근 30일)
  
       이전 댓글 표시
    
Im trying to do multiple legends for each of my polar plots, I want a legend on each one stating the two months that are on the plot. When I put down my first two (jan and feb) they go onto everyone plot and im not sure how to change it so it will change for each plot.
for ii = 1:2:12
    plotIndex1 = (month(datetime(windTurbineData.disc_TimeStamp))==ii);
    plotIndex2 = (month(datetime(windTurbineData.disc_TimeStamp))==ii+1);
    hs = subplot(2,3,(ii+1)/2,polaraxes);
    polarplot(windTurbineData.mean_NacelleOrientation_Deg(plotIndex1==1,:)*pi/180,windTurbineData.mean_Power_kW(plotIndex1==1,:),'.','color',rainbow(ii,:))
    hold on
    polarplot(windTurbineData.mean_NacelleOrientation_Deg(plotIndex2==1,:)*pi/180,windTurbineData.mean_Power_kW(plotIndex2==1,:),'.','color',rainbow(ii+1,:))
    hold on
    hs.ThetaDir = 'clockwise';
    hs.ThetaZeroLocation = 'top';
    hs.ThetaTick = [0,45,90,135,180,225,270,315];
    hs.ThetaTickLabel = {'N','NE','E','SE','S','SW','W','NW'};
    hs.RTick = [4000,8000];
    hs.RTickLabel = {'4MW','8MW'};
    hs.FontSize = 10;
    rlim([0,8000])
    legend('Jan 19','Feb 19',)
end
댓글 수: 0
채택된 답변
  Jon
      
 2021년 12월 6일
        
      편집: Jon
      
 2021년 12월 6일
  
      There might be more elegant ways of generating the legends but one approach would be to define before the loop a cell array of legend entries, and then assign them in the loop
So ahead of the loop
legendTxt = legendTxt = {'Jan 19','Feb 19';'March 19', 'April 19';'May 19', 'June 19';...' ...
    'July 19', 'August 19';'Sept 19', 'Oct 19';'Nov 19', 'Dec 19'}
and then in the loop
l
legend(legendTxt{ceil(ii/2),:}) % ii goes 1,3,5 ceil(ii/2) gives 1,2,3..6 which is what we want
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
				Help Center 및 File Exchange에서 Polar Plots에 대해 자세히 알아보기
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

