Different legends for multiple graphs
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposta accettata
Jon
il 6 Dic 2021
Modificato: Jon
il 6 Dic 2021
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 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Legend in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!