Help with polar contour plots
7 views (last 30 days)
Show older comments
I am trying to plot the variable MW_FINAL in filled polar contour plot. The plot must look like the attached image. Below is the code I used to find MW_FINAL. The reqired data files are also attached.
close all;clear all;clc
format short g
wazim = 0:4:360;
wincli = 0:1:90;
mw_without_pw = importdata('MW WITHOUT POW.mat');
mw_on_pw = importdata('MW WITh POW amadei solution.mat');
for i = 1:length(wazim)
for j = 1:length(wincli)
if mw_without_pw(j,i) > mw_on_pw(j,i)
MW_FINAL(j,i) = mw_without_pw(j,i);
else
MW_FINAL(j,i) = mw_on_pw(j,i);
end
end
end
0 Comments
Answers (1)
Divyajyoti Nayak
on 17 Oct 2024
MATLAB does not have any direct way to create filled polar contour plots but from MATLAB R2024a, the "polarregion" function can be used as a workaround to programmatically create such plots. Do note that this approach is very graphically intensive. Here’s a documentation link to the "polarregion" function:
Here's the code I wrote for making the required plot:
close all;clear;clc
format short g
wazim = 0:4:360;
wincli = 0:1:90;
thetas = zeros(91);
radii = zeros(91);
mw_without_pw = importdata('MW WITHOUT POW.mat');
mw_on_pw = importdata('MW WITh POW amadei solution.mat');
for i = 1:length(wazim)
for j = 1:length(wincli)
if mw_without_pw(j,i) > mw_on_pw(j,i)
MW_FINAL(j,i) = mw_without_pw(j,i);
else
MW_FINAL(j,i) = mw_on_pw(j,i);
end
thetas(j,i) = wazim(i);
radii(j,i) = wincli(j);
end
end
n = numel(MW_FINAL);
cmap = turbo(n); %Creating a color map for data
%Mapping the data with the color map
cDataMap = (MW_FINAL - min(MW_FINAL,[], 'all'))/(max(MW_FINAL,[],'all')-min(MW_FINAL,[],'all')) * (n-1) + 1;
%Reshaping all data required for polarregion function
cDataMap = reshape(cDataMap,[8281,1]);
thetas = reshape(thetas,[8281,1]);
radii = reshape(radii,[8281,1]);
%Getting RGB values from color map using the mapped data
colorData = cmap(floor(cDataMap),:);
%Creating individual polar grid areas of the filled polar contour plot
pr = polarregion([(thetas-2),(thetas+2)]*pi/180,[(radii-0.5),(radii+0.5)]*pi/180,'FaceAlpha',1);
%Changing the color of each polarregion according to the color data
for i = 1:length(pr)
pr(i).FaceColor = colorData(i,:);
end
And here's the result:
0 Comments
See Also
Categories
Find more on Contour 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!