[Scilab-users] more polarplots in one coordinate system
Serge Steer
Serge.Steer at inria.fr
Mon Nov 28 21:30:10 CET 2016
Please find attached a new polarplot1 function which is able to do what
you want (some refinements may have to be done)
Example (sequences of polar plots)
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))
end
polarplot1(allphase,allmagnitude,colors(6))
Example (many plots with a simple call)
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)
Le 28/11/2016 à 16:01, Maxi041291 a écrit :
> Thank you for trying to help, but i think i didnt describe my Problem well
> enough.
> Normally there should be arrows in the plot, but i dont think this is
> possible in scilab.
>
> But here a Piece of my original code in scilab:
>
>
> clear;
> clc;
> 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];
> //This is how it works, but just for a defined length of the vectors
> clf(1);
> polarplot([phase(1:2) phase(2:3) phase(3:4) phase(4:5) phase(5:6)
> allphase],[magnitude(1:2) magnitude(2:3) magnitude(3:4) magnitude(4:5)
> magnitude(5:6) allmagnitude],[5,2,3,1,4,9]);
>
> //This is the way it doesnt work
> clf(2);
> polarplot(phase,magnitude,[5,2]);
> polarplot(allphase,allmagnitude,[1,2]);
>
>
>
>
> Because the length of the vectors (Magnitude and Phase) is not fixed in my
> original code, i think i cant define the polarplot like its done in the
> first example.
> So i would like to do it like in the second example, but that doesn´t work,
> because i get a new axis for each datapoint
>
>
>
>
>
> --
> View this message in context: http://mailinglists.scilab.org/more-polarplots-in-one-coordinate-system-tp4035127p4035130.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 --------------
// 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)
[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
rm=max(abs(rho))
x=rho.*cos(theta)
y=rho.*sin(theta)
xmin=min(x);
xmax=max(x);
ymin=min(y);
ymax=max(y);
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)
end
polargrid(xmin,xmax,ymin,ymax,rm)
for k=1:size(theta,2)
xpoly(x(:,k),y(:,k))
e=gce();
e.foreground=style(k)
end
drawnow()
endfunction
function 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="$\scriptstyle "+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