Plotting polarplot with 2 months in each from a 12 month dataset

12 views (last 30 days)
Sebastian Sunny
Sebastian Sunny on 3 Dec 2021
Edited: Stephen on 10 Dec 2021
Hi guys,
Ive been trying to implement a for-loop to plot graphs from a set data with each plot having 2 months in it, so the first plot would have all values from jan to feb and 2nd would have all values from march till april.
I also have been to trying to make the sets of data into 2 lines where the first is the plots for data constiting of jan to jun and the second line being data from jul to dec.
Thank you, any guidance would be appreciated
  1 Comment
Stephen
Stephen on 10 Dec 2021
Original question by Sebastion Sunny retrieved from Google Cache:
Plotting polarplot with 2 months in each from a 12 month dataset
Hi guys,
Ive been trying to implement a for-loop to plot graphs from a set data with each plot having 2 months in it, so the first plot would have all values from jan to feb and 2nd would have all values from march till april.
I also have been to trying to make the sets of data into 2 lines where the first is the plots for data constiting of jan to jun and the second line being data from jul to dec.
Thank you, any guidance would be appreciated
I have attached the corresponing data and a picture of what my plot should look like
sorry if my code is a bit chaotic:
t = month(windTurbineData.disc_TimeStamp);
R = deg2rad(windTurbineData.mean_NacelleOrientation_Deg);
for i = 1:2:12
i(1)= 1;
plotIndex1 = t == i;
plotIndex2 = t == (i+1);
hold on
subplot(2,3,1)
polarplot(R(plotIndex1),windTurbineData.mean_Power_kW(plotIndex1),'.');
polarplot(R(plotIndex2),windTurbineData.mean_Power_kW(plotIndex2),'.');
hold on
subplot(2,3,2)
polarplot(R(plotIndex1),windTurbineData.mean_Power_kW(plotIndex1),'.');
polarplot(R(plotIndex2),windTurbineData.mean_Power_kW(plotIndex2),'.');
hold on
subplot(2,3,3)
polarplot(R(plotIndex1),windTurbineData.mean_Power_kW(plotIndex1),'.');
polarplot(R(plotIndex2),windTurbineData.mean_Power_kW(plotIndex2),'.');
hold on
subplot(2,3,4)
polarplot(R(plotIndex1),windTurbineData.mean_Power_kW(plotIndex1),'.');
polarplot(R(plotIndex2),windTurbineData.mean_Power_kW(plotIndex2),'.');
hold on
subplot(2,3,5)
polarplot(R(plotIndex1),invalidDataIndex(plotIndex1),'.');
polarplot(R(plotIndex2),invalidDataIndex(plotIndex2),'.');
hold on
subplot(2,3,6)
polarplot(R(plotIndex1),invalidDataIndex(plotIndex1),'.');
polarplot(R(plotIndex2),invalidDataIndex(plotIndex2),'.');
end
subplot(2,3,1)
thetaticks(gca,[0 45 90 135 180 225 270])
thetaticklabels(gca,{'E','NE','N','NW','W','SW','S'});
set(gca,'ColorOrder',cmap)
grid on
subplot(2,3,2)
thetaticks(gca,[0 45 90 135 180 225 270])
thetaticklabels(gca,{'E','NE','N','NW','W','SW','S'});
set(gca,'ColorOrder',cmap)
subplot(2,3,3)
thetaticks(gca,[0 45 90 135 180 225 270])
thetaticklabels(gca,{'E','NE','N','NW','W','SW','S'});
set(gca,'ColorOrder',cmap)
subplot(2,3,4)
thetaticks(gca,[0 45 90 135 180 225 270])
thetaticklabels(gca,{'E','NE','N','NW','W','SW','S'});
set(gca,'ColorOrder',cmap)
subplot(2,3,5)
thetaticks(gca,[0 45 90 135 180 225 270])
thetaticklabels(gca,{'E','NE','N','NW','W','SW','S'});
set(gca,'ColorOrder',cmap)
subplot(2,3,6)
thetaticks(gca,[0 45 90 135 180 225 270])
thetaticklabels(gca,{'E','NE','N','NW','W','SW','S'});
set(gca,'ColorOrder',cmap)

Sign in to comment.

Accepted Answer

Dave B
Dave B on 3 Dec 2021
You didn't say much about what's going wrong, but one thing I noticed is that your hold on statements are in the wrong spot. You have:
subplot(...)
polarplot(...);
polarplot(...);
hold on
But that says:
  1. make a new subplot
  2. call polarplot (which clears the axes because hold is off)
  3. call polarplot (which clears the axes because hold is off)
  4. turn hold on
Instead, try:
subplot(...)
polarplot(...);
hold on
polarplot(...);
A few other tips:
  • I'd recommend tiledlayout/nexttile instead of subplot. Before your loop call tiledlayout(2,3) then replace the subplots with nexttile (I don't think you'll need any arguments). These functions were introduced in R2019b.
  • I'd recommend polarscatter instead of polarplot. plot is great because it does everything, but scatter is better at making scatters.
  2 Comments
Dave B
Dave B on 4 Dec 2021
Here you go - I had missed the fact that you were looping over months but then calling subplot a bunch of times within the loop. Your original code needed a single call to subplot in the loop which had i in it.This worked for me (sorry can't run it here because the file is too large, but I'm showing the output below based on exportgraphics(gcf, 'foo.png')
  • I took a guess at the colors, you certainly can use whatever colormap you have.
  • There's a few ways to get this kind of cross-axes coloring to work well in MATLAB, and you certainly could do it with colormap instead of a colororder, but the latter makes for nice easy to read code (IMO).
  • If you need the "19" in the legends you can just add + "19" at the end of the DisplayName (after the close parentheses for the string function)
  • You might consider some transparency here, it's a little frustrating that one month obscures the other. You can set transparency with 'MarkerFaceAlpha', and a value between 0 and 1. There are a couple of more complex solutions for shuffling the stacking order, but they take some effort so I'll only walk through it if it's important.
windTurbineData=readtable("Levenmouth7MWTurbineData2019.csv");
t = month(windTurbineData.disc_TimeStamp);
R = deg2rad(windTurbineData.mean_NacelleOrientation_Deg);
tiledlayout(2,3)
for i = 1:2:12
nexttile
polarscatter(R(t==i),windTurbineData.mean_Power_kW(t==i),10,'filled', ...
'DisplayName',string(month(windTurbineData.disc_TimeStamp(find(t==i,1)),'shortname')), ... % long way of picking a name for the legend
'SeriesIndex', i) % this will be used for color
hold on
polarscatter(R(t==i+1),windTurbineData.mean_Power_kW(t==i+1),10,'filled', ...
'DisplayName',string(month(windTurbineData.disc_TimeStamp(find(t==i+1,1)),'shortname')), ... % long way of picking a name for the legend
'SeriesIndex', i+1) % this will be used for color
thetaticks([0 45 90 135 180 225 270])
thetaticklabels({'E','NE','N','NW','W','SW','S'});
legend('Location','northoutside','Orientation','horizontal')
end
clrs=["#FEBF15" "#D74523" "#C1FB13" "#41FB17" "#0BF944" "#17FDBE" "#17BDFD" "#183BF4" "#2A1CDC" "#BE35FD" "#FE28BB" "#FE1341"];
clrs=validatecolor(clrs,'multiple');
colororder(clrs)

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by