I have to plot antenna response pattern in a spherical polar plot.
I first create the theta(t
) and phi(p
) values. Then there is F_c and F_s that has to calculated for each theta[i]
and phi[i]
.
t=np.linspace(-math.pi/2, math.pi/2, num=x)
p=np.linspace(-math.pi, math.pi, num=x)
for k in xrange(x):
for j in xrange(x):
for i in xrange(n):
F_c=F_c_F_s.F_c(theta[i],phi[i],t[j],p[k])
F_s=F_c_F_s.F_s(theta[i],phi[i],t[j],p[k])
sum_F_c[j][k]=sum_F_c[j][k]+F_c
sum_F_s[j][k]=sum_F_s[j][k]+F_s
mod_F[j][k]=math.log((math.pow(sum_F_c[j][k],2)+math.pow(sum_F_s[j][k],2)),10)
Now we have a value of mod_F
for each t
and p
. For each value of theta and correspondingly for each value of phi I calculate Cartesian coordinates. Then to make the surface plot I have the following:
fig = p.figure()
ax = Axes3D(fig)
ax.plot_wireframe(x,y,z)
ax.plot_surface(x,y,z,rstride=1,cstride=1,cmap=cm.jet)
p.show()
The problem is, it is incredibly slow! Even for x=10
i.e. a 10 x 10 grid, it take a lot of time. Is there a way to do this in better and faster manner?
Following worked for me:
t=np.linspace(0, np.pi, num=x)
p=np.linspace(-np.pi,np.pi,num=x)
[T,P]=np.meshgrid(t,p)
F_c=0.0
F_s=0.0
for i in xrange(n):
F_c+=F_c_F_s.F_c(theta[i],phi[i],T,P)
F_s+=F_c_F_s.F_s(theta[i],phi[i],T,P)
mod_F=(np.log10((np.power(F_c,2)+np.power(F_s,2))))