I am trying to generate a normalized (to the max) wind rose plot of air pollutant concentration (UFP) by wind direction. See photo below. A data vector is attached. The simple code: polarplot(N.WD_Deg,N.UFPConc) doesn't generate what I want. Any help is appreciated. Thank you
load winddata.mat
polarplot(N.WD_Deg,N.UFPConc)

4 commentaires

VBBV
VBBV le 23 Juin 2023
Try using polarhistogram function
VBBV
VBBV le 23 Juin 2023
Déplacé(e) : VBBV le 25 Juin 2023
One way is to use the data for air pollution concentration directly and compare with direction data as shown below
Data = load('winddata.mat')
Data = struct with fields:
N: [133872×3 table]
Data.N;
%
subplot(121)
polarplot(Data.N.WD_Deg(1:10000:end),'linewidth',2,'Color','red')
title('Wind direction [deg]')
subplot(122) % normalized plot of air pollutant data
polarplot(Data.N.UFPConc(1:10000:end)./max(Data.N.UFPConc(1:10000:end)),'linewidth',2,'Color','red')
title('Air pollutant concentration')
since polarplot by default uses direction data for its axes, yoou can use that pollutant data directly. Othwerwise, you can also apply conditions for direction data bins and filter the air pollutant concentration data , then plot it. Further, the data points in the table are many, so its better to filter the air pollutant data using bin averaged directional means which will be representative of the air pollutant concentration
Douglas Leaffer
Douglas Leaffer le 24 Juin 2023
Déplacé(e) : VBBV le 25 Juin 2023
Thank you VBBV and Star Strider. Both of your suggested codes worked for me - but I can't seem to rotate the compass points to have 0 at the top and then clockwise ticks, with 90 deg at right, 180 at bottom and 270 at left. Is there a simple programmatic fix for this?
E. Cheynet
E. Cheynet le 25 Juin 2023
For the direction with meteorological conventions, you can simply give a new direction newD = 90-oldD

Connectez-vous pour commenter.

 Réponse acceptée

Perhaps something like this —
LD = load('winddata.mat');
N = LD.N;
N.WD_Rad = deg2rad(N.WD_Deg) % Add Radian Variable (For Convenience, Since 'polarplot' Requires It)
N = 133872×4 table
WD_Deg WS UFPConc WD_Rad ______ ______ _______ ______ 30 25.927 0.11886 0.5236 30 25.927 0.13314 0.5236 30 25.927 0.16629 0.5236 30 25.927 0.15657 0.5236 30 25.927 0.15257 0.5236 30 25.927 0.15486 0.5236 30 25.927 0.12457 0.5236 30 25.927 0.12457 0.5236 30 25.927 0.15829 0.5236 30 25.927 0.13657 0.5236 30 25.927 0.124 0.5236 30 25.927 0.108 0.5236 30 25.927 0.10343 0.5236 30 25.927 0.12914 0.5236 30 25.927 0.18229 0.5236 30 25.927 0.19371 0.5236
[UDir,ix,iv] = unique(N.WD_Rad); % Unique Radian Values & Indices (Sorted)
Concv = accumarray(iv, (1:numel(iv)).', [], @(x)numel(N.UFPConc(x))); % Accumulate Count Values Of 'UFPConc' By Direction (Use 'numel' To Count Occurrences)
[sDir, sConc] = stairs(UDir, Concv); % Return 'stairs' Stepwise Result
figure
polarplot(sDir, sConc) % Plot 'stairs' Stepwise Result
figure
polarplot(UDir, Concv) % Plot Continuous Result
figure
polarhistogram(N.WD_Rad, UDir) % Plot Using 'polarhistogram'
Make appropriate changes to get the result you want.
Using the accumarray function, it is possible to get other parameters of the concentration, such as the mean or median values, as well as standard deviations (std and metrics derived from it, such as confidence intervals) and plot them also using the patch function (although that is more complicated and requires calculating them in polar coordinates and then using the pol2cart function first, and plotting them in Cartesian coordinates), not only the counts.
.

4 commentaires

Douglas Leaffer
Douglas Leaffer le 24 Juin 2023
Thank you VBBV and Star Strider. Both of your suggested codes worked for me - but I can't seem to rotate the compass points to have 0 at the top and then clockwise ticks, with 90 deg at right, 180 at bottom and 270 at left. Is there a simple programmatic fix for this?
It is straightforward to add those using the ThetaZeroLocation and ThetaDir properties (that I believe existed before R2022a, so you should have them) —
LD = load('winddata.mat');
N = LD.N;
N.WD_Rad = deg2rad(N.WD_Deg) % Add Radian Variable (For Convenience, Since 'polarplot' Requires It)
N = 133872×4 table
WD_Deg WS UFPConc WD_Rad ______ ______ _______ ______ 30 25.927 0.11886 0.5236 30 25.927 0.13314 0.5236 30 25.927 0.16629 0.5236 30 25.927 0.15657 0.5236 30 25.927 0.15257 0.5236 30 25.927 0.15486 0.5236 30 25.927 0.12457 0.5236 30 25.927 0.12457 0.5236 30 25.927 0.15829 0.5236 30 25.927 0.13657 0.5236 30 25.927 0.124 0.5236 30 25.927 0.108 0.5236 30 25.927 0.10343 0.5236 30 25.927 0.12914 0.5236 30 25.927 0.18229 0.5236 30 25.927 0.19371 0.5236
[UDir,ix,iv] = unique(N.WD_Rad); % Unique Radian Values & Indices (Sorted)
Concv = accumarray(iv, (1:numel(iv)).', [], @(x)numel(N.UFPConc(x))); % Accumulate Count Values Of 'UFPConc' By Direction (Use 'numel' To Count Occurrences)
[sDir, sConc] = stairs(UDir, Concv); % Return 'stairs' Stepwise Result
figure
polarplot(sDir, sConc) % Plot 'stairs' Stepwise Result
Ax = gca;
Ax.ThetaZeroLocation = 'top';
Ax.ThetaDir = 'clockwise';
figure
polarplot(UDir, Concv) % Plot Continuous Result
Ax = gca;
Ax.ThetaZeroLocation = 'top';
Ax.ThetaDir = 'clockwise';
figure
polarhistogram(N.WD_Rad, UDir) % Plot Using 'polarhistogram'
Ax = gca;
Ax.ThetaZeroLocation = 'top';
Ax.ThetaDir = 'clockwise';
.
Douglas Leaffer
Douglas Leaffer le 24 Juin 2023
Excellent. It worked fine. Thank you
Star Strider
Star Strider le 24 Juin 2023
As always, my pleasure!

Connectez-vous pour commenter.

Plus de réponses (1)

Douglas Leaffer
Douglas Leaffer le 22 Déc 2023
Hello, it seems the plots generated from these suggested answers are not what I need. I need a normalized [0 1] wind rose of UFP (air pollution particle) by wind degree sector, as show in these 3 examples. My dataset is attached. The code I ran is given below. I could use some more help if anyone is able. Thank you.
load CR_1hr_wind.mat
NC = normalize(CT1,"norm",Inf,"DataVariables","UFPConc");
NC.WD_Rad = deg2rad(NC.WD_Deg) % Add Radian Variable (For Convenience, Since 'polarplot' Requires It)
[UDir,ix,iv] = unique(NC.WD_Rad); % Unique Radian Values & Indices (Sorted)
Concv = accumarray(iv, (1:numel(iv)).', [], @(x)numel(NC.UFPConc(x))); % Accumulate Count Values Of 'UFPConc' By Direction (Use 'numel' To Count Occurrences)
%[sDir, sConc] = stairs(UDir, Concv); % Return 'stairs' Stepwise Result
%figure
%polarplot(sDir, sConc)
figure
%subplot (121)
polarplot(UDir, Concv, 'LineWidth', 4) % Plot Continuous Result
Ax = gca;
Ax.ThetaZeroLocation = 'top';
Ax.ThetaDir = 'clockwise';

3 commentaires

To normalise them, divide by the maximum:
Concv = Concv/max(Concv);
Try this —
load CR_1hr_wind.mat
NC = normalize(CT1,"norm",Inf,"DataVariables","UFPConc");
NC.WD_Rad = deg2rad(NC.WD_Deg) % Add Radian Variable (For Convenience, Since 'polarplot' Requires It)
NC = 1887×4 table
WD_Deg WS UFPConc WD_Rad ______ ______ _______ _______ 320 14.816 0.65284 5.5851 310 16.668 0.58952 5.4105 350 11.112 0.83406 6.1087 340 12.964 0.80568 5.9341 80 16.668 0.76419 1.3963 90 14.816 0.6441 1.5708 80 24.075 0.50655 1.3963 70 25.927 0.50655 1.2217 70 24.075 0.5262 1.2217 80 18.52 0.57205 1.3963 60 14.816 0.58079 1.0472 50 12.964 0.73362 0.87266 40 14.816 0.50873 0.69813 50 7.4078 0.63755 0.87266 360 7.4078 0.48472 6.2832 0 0 0.6441 0
[UDir,ix,iv] = unique(NC.WD_Rad); % Unique Radian Values & Indices (Sorted)
Concv = accumarray(iv, (1:numel(iv)).', [], @(x)numel(NC.UFPConc(x))); % Accumulate Count Values Of 'UFPConc' By Direction (Use 'numel' To Count Occurrences)
%[sDir, sConc] = stairs(UDir, Concv); % Return 'stairs' Stepwise Result
%figure
%polarplot(sDir, sConc)
Concv = Concv/max(Concv);
figure
%subplot (121)
polarplot(UDir, Concv, 'LineWidth', 4) % Plot Continuous Result
Ax = gca;
Ax.ThetaZeroLocation = 'top';
Ax.ThetaDir = 'clockwise';
If you want to scale over different limits, use the rescale function.
If you intend something else, please be specific.
.
Douglas Leaffer
Douglas Leaffer le 22 Déc 2023
That seems to be more of what I need. Thanks again
Star Strider
Star Strider le 22 Déc 2023
As always, my pleasure!

Connectez-vous pour commenter.

Catégories

En savoir plus sur Polar Plots dans Centre d'aide et File Exchange

Produits

Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by