Different legends for multiple graphs

7 views (last 30 days)
PureFleet on 6 Dec 2021
Edited: Jon on 6 Dec 2021
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);
hold on
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;
legend('Jan 19','Feb 19',)

Accepted Answer

Jon on 6 Dec 2021
Edited: Jon on 6 Dec 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
legend(legendTxt{ceil(ii/2),:}) % ii goes 1,3,5 ceil(ii/2) gives 1,2,3..6 which is what we want

More Answers (0)


Find more on Data Distribution Plots 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!

Translated by