1 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 // Copyright (C) 2010 - DIGITEO - Manuel Juliachs
4 // Copyright (C) 2012 - 2016 - Scilab Enterprises
5 // Copyright (C) 2010, 2018 - Samuel GOUGEON
7 // This file is hereby licensed under the terms of the GNU GPL v2.0,
8 // pursuant to article 5.3.4 of the CeCILL v.2.1.
9 // This file was originally licensed under the terms of the CeCILL v2.1,
10 // and continues to be available under such terms.
11 // For more information, see the COPYING file which you should have received
12 // along with this program.
14 function polarplot(theta,rho,style,strf,leg,rect)
18 rho=sin(2*theta).*cos(2*theta)
19 s = gca().axes_bounds;
20 delete(gca()); xsetech(s) // clears & keeps the current axes area
24 if size(theta,1)==1 then
27 if size(rho,1)==1 then
38 if exists("style","local")==1 then
39 opts=[opts,"style=style"]
41 if exists("strf","local")==1 then
42 opts=[opts,"strf=strf"]
45 if exists("leg","local")==1 then
48 if exists("rect","local")==1 then
49 opts=[opts,"rect=rect"]
52 if exists("frameflag","local")==1 then
53 opts=[opts,"frameflag=frameflag"]
57 if size(opts,2)<rhs-2 then
58 error(msprintf(gettext("%s: Wrong value for input argument: ''%s'', ''%s'', ''%s'', ''%s'' or ''%s'' expected.\n"),"polarplot","style","strf","leg","rect","frameflag"));
61 // Some default values:
62 Amin=0 // starting angle for the frame
63 dA=360 // span of the angular frame
64 nn=4 // number of quadrants to be drawn
72 // Angle at which Radial labels will be displayed
73 A=round(atan((ymin+ymax)/2,(xmin+xmax)/2)/%pi*180/45)*45;
74 dx=-0.5, dy=-0.5 // H & V shifts in string-width and string-height units
78 // Determines quadrant(s) to be drawn
106 L=(xmax-xmin)*1.1; if L==0, L=2*rm*1.1; end
107 H=(ymax-ymin)*1.1; if H==0, H=2*rm*1.1; end
108 x0=(xmin+xmax)/2; y0=(ymin+ymax)/2;
109 rect=[x0-L/2 y0-H/2 x0+L/2 y0+H/2]
111 // Special case: data aligned on the x or y axis
113 if (ymax-ymin)<2*e, // on x axis
130 n=find(Q); // id numbers of quadrants to be drawn
131 nn=length(n) // number of quadrants to be drawn
137 if n==1, A=90, dx=-1.1, dy=-0.5
138 elseif n==2, A=90, dx=0.2, dy=-0.5
139 elseif n==3, A=270, dx=0.2, dy=-0.5
140 else A=270, dx=-1.1, dy=-0.5
145 if n(2)==2, //A=90, dx=0.1, dy=-0.5
146 else Amin=-90, A=90, dx=-1.2, dy=-0.5, end
147 elseif n(1)==2, A=90, dx=0.2, dy=-0.5
148 else A=0, dx=-0.5, dy=0.2
153 opts=[opts,"rect=rect"]
156 if isstrf& isframeflag then
157 error(msprintf(gettext("%s: ''%s'' cannot be used with ''%s''.\n"),"polarplot","frameflag","strf"));
161 opts=[opts,"axesflag=axesflag"],
163 if ~(isstrf|isframeflag) then
165 opts=[opts,"frameflag=frameflag"],
168 initDrawingMode = gcf().immediate_drawing;
169 gcf().immediate_drawing = "off";
170 execstr("plot2d(x,y,"+strcat(opts,",")+")")
172 fcolor=color("grey70");
175 // Radial values for the frame:
176 fmt_in=format(), format("v",9)
177 // Tunning for smart values:
178 p=floor(log10(abs(rm)));
186 if m-k*dm < dm/5, k=k-1, end
188 // Tuning for smart 10^ display using LaTeX instead of D+## exponential display
191 [v,k]=max(length(Rtxt))
192 tmp=xstringl(0,0,Rtxt(k))
194 if dm<1, dm=dm*10, p=p-1, end
195 tmp = string(R/10^p)+"108"
196 [v,k] = max(length(tmp))
197 tmp = xstringl(0,0,tmp(k))
198 Rtxt = "$\scriptstyle "+string(R/10^p)+"\:.10^{"+string(p)+"}$";
200 w = tmp(3); h = tmp(4);
201 format(fmt_in(2),fmt_in(1)) // Restoring entrance format
204 // Drawing & labelling the radial frame
208 xarc(-r,r,2*r,2*r,Amin*64,dA*64)
211 e.foreground = fcolor;
213 e.line_style=1; // solid outer arc
215 xstring(r*cosd(A)+w*dx, r*sind(A)+h*dy, Rtxt(k))
217 e.clip_state = "off";
222 if nn<3, eA=10, else eA=30; end // adaptative angular sampling
223 an=linspace(Amin,Amin+dA,round(dA/eA)+1);
225 if nn>2, tmp=find(abs(an-360)<eA/10); an(tmp)=[]; end
226 // Adjusting H-shifts of angular labels
227 tmp=xstringl(0,0,"360");
229 rL=rm*1.03; // Radius of angular labels
230 for k=an // draws and labels angular rays
231 xsegs([0;rm*cosd(k)],[0;rm*sind(k)])
233 e.segs_color = fcolor;
235 xstring((rL+w/2)*cosd(k)-w/2, (rL+h/2)*sind(k)-h/2, string(k))
237 e.clip_state = "off";
241 a.data_bounds=[rect(1:2);rect(3:4)]
242 a.margins=[0.07 0.07 0.12 0.07]
244 gcf().immediate_drawing = initDrawingMode;