Skip to content

Commit c545a6d

Browse files
authored
Add files via upload
1 parent a125a53 commit c545a6d

File tree

2 files changed

+65
-71
lines changed

2 files changed

+65
-71
lines changed

Example.mlx

-99.1 KB
Binary file not shown.

polarPcolor.m

Lines changed: 65 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11

22
function [varargout] = polarPcolor(R,theta,Z,varargin)
3-
% [h,c] = polarPcolor1(R,theta,Z,varargin) is a pseudocolor plot of matrix
4-
% Z for a vector radius R and a vector angle theta.
5-
% The elements of Z specify the color in each cell of the
6-
% plot. The goal is to apply pcolor function with a polar grid, which
3+
% [h,c] = polarPcolor1(R,theta,Z,varargin) is a pseudocolor plot of matrix
4+
% Z for a vector radius R and a vector angle theta.
5+
% The elements of Z specify the color in each cell of the
6+
% plot. The goal is to apply pcolor function with a polar grid, which
77
% provides a better visualization than a cartesian grid.
88
%
99
%% Syntax
10-
%
10+
%
1111
% [h,c] = polarPcolor(R,theta,Z)
1212
% [h,c] = polarPcolor(R,theta,Z,'Ncircles',10)
1313
% [h,c] = polarPcolor(R,theta,Z,'Nspokes',5)
14-
% [h,c] = polarPcolor(R,theta,Z,'Nspokes',5,'colBar',0)
14+
% [h,c] = polarPcolor(R,theta,Z,'Nspokes',5,'colBar',0)
1515
% [h,c] = polarPcolor(R,theta,Z,'Nspokes',5,'labelR','r (km)')
16-
%
16+
%
1717
% INPUT
1818
% * R :
1919
% - type: float
2020
% - size: [1 x Nrr ] where Nrr = numel(R).
2121
% - dimension: radial distance.
22-
% * theta :
22+
% * theta :
2323
% - type: float
2424
% - size: [1 x Ntheta ] where Ntheta = numel(theta).
2525
% - dimension: azimuth or elevation angle (deg).
2626
% - N.B.: The zero is defined with respect to the North.
27-
% * Z :
27+
% * Z :
2828
% - type: float
2929
% - size: [Ntheta x Nrr]
3030
% - dimension: user's defined .
@@ -40,13 +40,13 @@
4040
% - ncolor: Number of colors in the colorbar and pcolor
4141
% - circlesPos: position of the circles with respect to the origin
4242
% (it overwrites Ncircles if necessary)
43-
%
44-
%
43+
%
44+
%
4545
% OUTPUT
4646
% h: returns a handle to a SURFACE object.
4747
% c: returns a handle to a COLORBAR object.
4848
%
49-
%% Examples
49+
%% Examples
5050
% R = linspace(3,10,100);
5151
% theta = linspace(0,180,360);
5252
% Z = linspace(0,10,360)'*linspace(0,10,100);
@@ -56,7 +56,7 @@
5656
%% Author
5757
% Etienne Cheynet, University of Stavanger, Norway. 23/10/2019
5858
% see also pcolor
59-
%
59+
%
6060
%% InputParseer
6161
p = inputParser();
6262
p.CaseSensitive = false;
@@ -100,21 +100,17 @@
100100
end
101101
if isempty(circPos)
102102
if ~isempty(RtickLabel)
103-
if numel(RtickLabel)~=Ncircles
103+
if numel(RtickLabel)~=Ncircles
104104
error(' The radial ticklabel must be equal to Ncircles');
105105
end
106106
if any(cellfun(@ischar,RtickLabel)==0)
107107
error(' The radial ticklabel must be a cell array of characters');
108108
end
109-
end
109+
end
110110
end
111111
if ~isempty(circPos)
112112
circPos = unique([min(R),circPos,max(R)]);
113113
end
114-
115-
116-
117-
118114
%% Preliminary checks
119115
% case where dimension is reversed
120116
Nrr = numel(R);
@@ -131,14 +127,10 @@
131127
error(' dimension of Z does not agree with dimension of R and Theta')
132128
end
133129
%% data plot
134-
135-
136-
137130
rMin = min(R);
138131
rMax = max(R);
139132
thetaMin=min(theta);
140133
thetaMax =max(theta);
141-
142134
if strcmpi(typeRose,'meteo')
143135
theta = theta;
144136
elseif strcmpi(typeRose,'default')
@@ -276,12 +268,8 @@ function createCircles(rMin,rMax,thetaMin,thetaMax,Ncircles,circlePos,Nspokes)
276268
error('"type" must be "meteo" or "default" ');
277269
end
278270

279-
280-
281-
282271
xGrid = cosd(angleGrid);
283272
yGrid = sind(angleGrid);
284-
285273
spokeMesh = linspace(thetaMin,thetaMax,Nspokes);
286274

287275
% plot circles
@@ -291,71 +279,77 @@ function createCircles(rMin,rMax,thetaMin,thetaMax,Ncircles,circlePos,Nspokes)
291279
plot(X,Y,'color',[0.5,0.5,0.5],'linewidth',1);
292280
end
293281
% radius tick label
294-
for kk=1:Ncircles
295-
296-
position = 0.51.*(spokeMesh(min(Nspokes,round(Ncircles/2)))+...
297-
spokeMesh(min(Nspokes,1+round(Ncircles/2))));
298282

299-
if strcmpi(typeRose,'meteo'),position = 90-position; end
300-
if strcmpi(typeRose,'default') && min(90-theta)<5,position = 0; end
301-
if min(round(theta))==90 && strcmpi(typeRose,'meteo'), position = 0; end
302-
283+
position = 0.51.*(spokeMesh(min(Nspokes,round(Ncircles/2)))+...
284+
spokeMesh(min(Nspokes,1+round(Ncircles/2))));
285+
if strcmpi(typeRose,'meteo'),position = 90-position; end
286+
if strcmpi(typeRose,'default') && min(90-theta)<5,position = 0; end
287+
if min(round(theta))==90 && strcmpi(typeRose,'meteo'), position = 0; end
288+
if max(round(theta))==90 && strcmpi(typeRose,'meteo'), position = 0; end
289+
290+
for kk=1:Ncircles
303291
if isempty(RtickLabel),
304292
rtick = num2str(tickMesh(kk),2);
305293
else
306294
rtick = RtickLabel(kk);
307295
end
308-
if abs(round(position)) ==90,
309-
% radial graduations
310-
t = text((contourD(kk)).*cosd(position),...
311-
(0.1+contourD(kk)).*sind(position-4),...
312-
rtick,'verticalalignment','BaseLine',...
313-
'horizontalAlignment', 'center',...
314-
'handlevisibility','off','parent',cax);
315-
% annotate spokes
316-
text(contourD(end).*0.6.*cosd(position),...
317-
0.07+contourD(end).*0.6.*sind(position),...
296+
297+
% radial graduations
298+
t = text(contourD(kk).*cosd(position),...
299+
(contourD(kk)).*sind(position),...
300+
rtick,'verticalalignment','BaseLine',...
301+
'horizontalAlignment', 'right',...
302+
'handlevisibility','off','parent',cax);
303+
if min(round(abs(90-theta)))<5 && strcmpi(typeRose,'default'),
304+
t.Position = t.Position - [0,0.1,0];
305+
t.Interpreter = 'latex';
306+
clear t;
307+
end
308+
if min(round(theta))==90 && strcmpi(typeRose,'meteo')
309+
t.Position = t.Position + [0,0.02,0];
310+
t.Interpreter = 'latex';
311+
clear t;
312+
elseif max(round(theta))==90 && strcmpi(typeRose,'meteo')
313+
t.Position = t.Position - [0,0.05,0];
314+
t.Interpreter = 'latex';
315+
clear t;
316+
end
317+
318+
% annotate spokes
319+
if max(theta)-min(theta)>180,
320+
t = text(contourD(end).*1.3.*cosd(position),...
321+
contourD(end).*1.3.*sind(position),...
318322
[labelR],'verticalalignment','bottom',...
319323
'horizontalAlignment', 'right',...
320324
'handlevisibility','off','parent',cax);
321325
else
322-
% radial graduations
323-
t = text(contourD(kk).*cosd(position),...
324-
(contourD(kk)).*sind(position),...
325-
rtick,'verticalalignment','BaseLine',...
326-
'horizontalAlignment', 'right',...
327-
'handlevisibility','off','parent',cax);
328-
if min(round(abs(90-theta)))<5 && strcmpi(typeRose,'default'),
329-
t.Position = t.Position - [0,0.05,0];
330-
t.Interpreter = 'latex';
331-
clear t;
332-
end
333-
if min(round(theta))==90 && strcmpi(typeRose,'meteo'),
334-
t.Position = t.Position + [0,0.02,0];
335-
t.Interpreter = 'latex';
336-
clear t;
337-
end
338-
% annotate spokes
339326
t = text(contourD(end).*0.6.*cosd(position),...
340327
contourD(end).*0.6.*sind(position),...
341328
[labelR],'verticalalignment','bottom',...
342329
'horizontalAlignment', 'right',...
343330
'handlevisibility','off','parent',cax);
344-
t.Interpreter = 'latex';
345-
if min(round(theta))==90 && strcmpi(typeRose,'meteo'), t.Position = t.Position + [0,0.05,0]; clear t; end
346-
if min(round(abs(90-theta)))<5 && strcmpi(typeRose,'default'),
347-
t.Position = t.Position - [0,0.12,0];
348-
t.Interpreter = 'latex';
349-
clear t;
350-
end
351331
end
332+
333+
t.Interpreter = 'latex';
334+
if min(round(theta))==90 && strcmpi(typeRose,'meteo'),
335+
t.Position = t.Position + [0,0.05,0];
336+
clear t;
337+
elseif max(round(theta))==90 && strcmpi(typeRose,'meteo'),
338+
t.Position = t.Position + [0,0.05,0];
339+
clear t;
340+
end
341+
% if min(round(abs(90-theta)))<5 && strcmpi(typeRose,'default'),
342+
% t.Position = t.Position - [0,0.12,0];
343+
% t.Interpreter = 'latex';
344+
% clear t;
345+
% end
352346
end
353347

354348
end
355349
function [rNorm] = getRnorm(Rscale,Origin,R,Rrange)
356350
if strcmpi(Rscale,'linear')||strcmpi(Rscale,'lin')
357-
rNorm = R-R(1)+Origin;
358-
rNorm = (rNorm)/max(rNorm)*max(R/Rrange);
351+
rNorm = R-R(1)+Origin;
352+
rNorm = (rNorm)/max(rNorm)*max(R/Rrange);
359353
elseif strcmpi(Rscale,'log')||strcmpi(Rscale,'logarithmic')
360354
if rMin<=0
361355
error(' The radial vector cannot be lower or equal to 0 if the logarithmic scale is used');

0 commit comments

Comments
 (0)