[Scilab-users] more polarplots in one coordinate system
Serge Steer
Serge.Steer at inria.fr
Wed Nov 30 12:06:10 CET 2016
Please find attached a revision of the polarplot1 function wich allows
to request a full 4 quadrants polar plot.
and below an example with arrowed lines
phase=[0;-2.8487;-2.993; 2.9664;2.8264;2.9638];
magnitude=[0;1.25e-4;2.17e-4;1.34e-4;7.5e-5;1.32e-4];
allmagnitude=[0; 1.32e-4];
allphase=[0;2.9638];
colors=[5,2,3,1,4,9];
clf
for k=1:size(phase,"*")-1
polarplot1(phase(k:k+1),magnitude(k:k+1),colors(k),%t)
e=gce();e.children(1).polyline_style=4; //arrowed style polylines
end
polarplot1(allphase,allmagnitude,colors(6),%t)
e=gce();e.children(1).polyline_style=4; //arrowed style polylines
or
clf;
phi=[];mag=[];
for k=1:size(phase,"*")-1
phi=[phi phase(k:k+1)];
mag=[mag magnitude(k:k+1)];
end
phi=[phi allphase];
mag=[mag allmagnitude];
polarplot1(phi,mag,colors,%t)
e=gce();e.children(1:$-1).polyline_style=4;
Le 30/11/2016 à 08:27, Maxi041291 a écrit :
> Hello again,
>
> Its just shown the part of the polarplot, which is used, but i would like to
> see the plot from 0° to 360°.
> how do i set the angle axis from 0° to 360° every time?
>
> Thank you for helping :)
>
>
>
>
>
> --
> View this message in context: http://mailinglists.scilab.org/more-polarplots-in-one-coordinate-system-tp4035127p4035146.html
> Sent from the Scilab users - Mailing Lists Archives mailing list archive at Nabble.com.
> _______________________________________________
> users mailing list
> users at lists.scilab.org
> http://lists.scilab.org/mailman/listinfo/users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20161130/def97911/attachment.htm>
-------------- next part --------------
// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
// Copyright (C) INRIA
// Copyright (C) 2010 - DIGITEO - Manuel Juliachs
// Copyright (C) 2012 - 2016 - Scilab Enterprises
//
// This file is hereby licensed under the terms of the GNU GPL v2.0,
// pursuant to article 5.3.4 of the CeCILL v.2.1.
// This file was originally licensed under the terms of the CeCILL v2.1,
// and continues to be available under such terms.
// For more information, see the COPYING file which you should have received
// along with this program.
function polarplot1(theta,rho,style,full)
[lhs,rhs]=argn(0)
if rhs<=0 then
theta=0:.01:2*%pi;
rho=sin(2*theta).*cos(2*theta)
clf();
polarplot(theta,rho)
return
end
if size(theta,1)==1 then
theta=theta(:),
end
if size(rho,1)==1 then
rho=rho(:),
end
if rhs<4 then full=%f;end
rm=max(abs(rho))
x=rho.*cos(theta)
y=rho.*sin(theta)
if full then
xmax=max(abs(x));
xmin=-xmax
ymax=max(abs(y));
ymin=-ymax
else
xmin=min(x);
xmax=max(x);
ymin=min(y);
ymax=max(y);
end
drawlater()
a=gca();
if a.tag=="polarplot" then
//clear grid
delete(a.user_data.grid);
bnds=a.user_data.bounds
xmin=min(bnds(1),xmin)
xmax=max(bnds(2),xmax)
ymin=min(bnds(3),ymin)
ymax=max(bnds(4),ymax)
rm=max(bnds(5),rm)
c=a.children
g=polargrid(xmin,xmax,ymin,ymax,rm)
//put the grid on the background
for k=1:size(c,'*')
swap_handles(c(k),g)
end
else
polargrid(xmin,xmax,ymin,ymax,rm)
end
C=[]
for k=1:size(theta,2)
xpoly(x(:,k),y(:,k))
e=gce();
e.foreground=style(k)
C=[e C];
end
glue(C)
drawnow()
endfunction
function G=polargrid(xmin,xmax,ymin,ymax,rm)
// Some default values:
Amin=0 // starting angle for the frame
dA=360 // span of the angular frame
nn=4 // number of quadrants to be drawn
// Angle at which Radial labels will be displayed
A=round(atan((ymin+ymax)/2,(xmin+xmax)/2)/%pi*180/45)*45;
dx=-0.5, dy=-0.5 // H & V shifts in string-width and string-height units
L=(xmax-xmin)*1.07;
H=(ymax-ymin)*1.07;
//determine Qudrants to be drawn
Q=[%T %T %T %T];
e=rm/500;
if xmin<-e then
xmin=-rm;
else
xmin=0; Q([2 3])=%F;
end
if xmax>e then
xmax= rm;
else
xmax=0; Q([1 4])=%F;
end
if ymin<-e then
ymin=-rm;
else
ymin=0; Q([3 4])=%F;
end
if ymax>e then
ymax= rm;
else
ymax=0; Q([1 2])=%F;
end
L=(xmax-xmin)*1.1; if L==0, L=2*rm*1.1; end
H=(ymax-ymin)*1.1; if H==0, H=2*rm*1.1; end
x0=(xmin+xmax)/2; y0=(ymin+ymax)/2;
rect=[x0-L/2 y0-H/2 x0+L/2 y0+H/2]
// Special case: data aligned on the x or y axis
if Q==[%F %F %F %F],
if (ymax-ymin)<2*e, // on x axis
if xmin<-e then
Q([2 3])=%T
end
if xmax> e then
Q([1 4])=%T
end
else // on y axis
if ymin<-e then
Q([3 4])=%T
end
if ymax> e then
Q([1 2])=%T
end
end
end
n=find(Q); // id numbers of quadrants to be drawn
nn=length(n) // number of quadrants to be drawn
Amin=(n(1)-1)*90
select nn
case 1,
dA=90;
if n==1, A=90, dx=-1.1, dy=-0.5
elseif n==2, A=90, dx=0.2, dy=-0.5
elseif n==3, A=270, dx=0.2, dy=-0.5
else A=270, dx=-1.1, dy=-0.5
end
case 2
dA=180;
if n(1)==1
if n(2)==2, //A=90, dx=0.1, dy=-0.5
else Amin=-90, A=90, dx=-1.2, dy=-0.5, end
elseif n(1)==2, A=90, dx=0.2, dy=-0.5
else A=0, dx=-0.5, dy=0.2
end
else
Amin=0, dA=360
end
fcolor=color("grey70");
xset("dashes",1)
// CIRCULAR FRAME:
// Radial values for the frame:
fmt_in=format(), format("v",9)
// Tunning for smart values:
p=floor(log10(abs(rm)));
m=rm/10^p;
if m<1.3, dm=0.2
elseif m<=2, dm=0.3
elseif m<4, dm=0.5
else dm=1,
end
k=fix(m/dm)
if m-k*dm < dm/5, k=k-1, end
R=[(1:k)*dm*10^p ]
// Tuning for smart 10^ display using LaTeX instead of D+## exponential display
if abs(p)<4,
Rtxt=string(R)
[v,k]=max(length(Rtxt)), tmp=xstringl(0,0,Rtxt(k))
else
if dm<1, dm=dm*10, p=p-1, end
tmp=string(R/10^p)+"108"
[v,k]=max(length(tmp)), tmp=xstringl(0,0,tmp(k))
Rtxt="$\small \bf "+string(R/10^p)+"\:.10^{"+string(p)+"}$";
end
w=tmp(3); h=tmp(4);
format(fmt_in(2),fmt_in(1)) // Restoring entrance format
R = [ R rm ]
G=[]
// Drawing & labelling the radial frame
kM=size(R,"*");
for k=1:kM
r=R(k)
xarc(-r,r,2*r,2*r,Amin*64,dA*64)
e = gce();,e.line_style=3
e.foreground=fcolor;
G=[e G]
if k==kM
e.line_style=1; // solid outer arc
else
xstring(r*cosd(A)+w*dx, r*sind(A)+h*dy, Rtxt(k))
e = gce();
e.clip_state = "off";
G=[e G]
end
end
// ANGULAR FRAME:
if nn<3, eA=10, else eA=30; end // adaptative angular sampling
an=linspace(Amin,Amin+dA,round(dA/eA)+1);
// avoiding 360 == 0
if nn>2, tmp=find(abs(an-360)<eA/10); an(tmp)=[]; end
// Adjusting H-shifts of angular labels
tmp=xstringl(0,0,"360");
w=tmp(3); h=tmp(4);
rL=rm*1.03; // Radius of angular labels
for k=an // draws and labels angular rays
xsegs([0;rm*cosd(k)],[0;rm*sind(k)])
e = gce(); e.segs_color=fcolor; e.line_style=3;
G=[e G]
xstring((rL+w/2)*cosd(k)-w/2, (rL+h/2)*sind(k)-h/2, string(k))
e = gce();
e.clip_state = "off";
G=[e G]
end
G=glue(G)
a=gca();
a.tag="polarplot"
a.user_data=struct("bounds",[xmin,xmax,ymin,ymax,rm],"grid",G)
a.data_bounds=[rect(1:2);rect(3:4)]
a.margins=[0.07 0.07 0.12 0.07]
a.isoview="on"
endfunction
More information about the users
mailing list