|||
画多个圈的时候才深刻体会到程序模块化的好处。毕竟重复操作不需要重复写代码。能让计算机做的事就不要自己做,计算机比人快得多还比较准确。
import matplotlib.pyplot as plt
from pylab import *
def plotmultibeam(x,y,angle):
x0=x
y0=y
angle=angle/180.0*np.pi
fig=plt.figure()
ax=fig.add_subplot(111)
beam=2.95
d=beam*2
circle=[]
circtemp=Circle(xy=(x0,y0),radius=beam/2,)
circle.append(circtemp)
plt.annotate('0,0',xy=(x0,y0))
plt.annotate('1',xy=(x0,y0-0.5),color='red')
for i in range(1,7,1):
xtemp=x0+d*np.cos(np.pi/3.0*i+angle)
ytemp=y0+d*np.sin(np.pi/3.0*i+angle)
strtemp=str('%6.2f'%(d*np.cos(np.pi/3.0*i+angle)))+','+str('%6.2f'%(d*np.sin(np.pi/3.0*i+angle)))
circtemp=Circle(xy=(xtemp,ytemp),radius=beam/2,)
circle.append(circtemp)
plt.annotate(strtemp,xy=(xtemp,ytemp))
beamnum=i-1
if(beamnum<2):
beamnum=beamnum+6
plt.annotate(str(beamnum),xy=(xtemp,ytemp-0.5),color='red')
d2=np.sqrt((d*np.cos(np.pi/3.0)+d)**2+(d*np.sin(np.pi/3.0))**2)
for i in range(1,7,1):
xtemp=x0+d2*np.cos(np.pi/3.0*(i-1)+np.pi/6.0+angle)
ytemp=y0+d2*np.sin(np.pi/3.0*(i-1)+np.pi/6.0+angle)
strtemp=str('%6.2f'%(d2*np.cos(np.pi/3.0*(i-1)+np.pi/6.0+angle)))+','+str('%6.2f'%(d2*np.sin(np.pi/3.0*(i-1)+np.pi/6.0+angle)))
circtemp=Circle(xy=(xtemp,ytemp),radius=beam/2,)
circle.append(circtemp)
plt.annotate(strtemp,xy=(xtemp,ytemp))
beamnum=i*2+1
if(beamnum<9):
beamnum=beamnum+12
plt.annotate(str(beamnum),xy=(xtemp,ytemp-0.5),color='red')
d3=d*2
for i in range(1,7,1):
xtemp=x0+d3*np.cos(np.pi/3.0*i+angle)
ytemp=y0+d3*np.sin(np.pi/3.0*i+angle)
strtemp=str('%6.2f'%(d3*np.cos(np.pi/3.0*i+angle)))+','+str('%6.2f'%(d3*np.sin(np.pi/3.0*i+angle)))
circtemp=Circle(xy=(xtemp,ytemp),radius=beam/2,)
circle.append(circtemp)
plt.annotate(strtemp,xy=(xtemp,ytemp))
beamnum=i*2+2
if(beamnum<8):
beamnum=beamnum+12
plt.annotate(str(beamnum),xy=(xtemp,ytemp-0.5),color='red')
for circ in circle:
circ.set_alpha(1.0)
circ.set_edgecolor([0.0,1.0,0.0])
circ.set_fill(False)
circ.set_linewidth(0.5)
ax.add_patch(circ)
x,y=0,0
#ax.plot(x,y,'ro')
ax.set_xlim(-10,10)
ax.set_ylim(-10,10)
xlabel('arcmin')
ylabel('arcmin')
plt.axis('equal')
filename='multibeam_position'+str(angle*180.0/np.pi)+'.png'
plt.savefig(filename)
plt.show()
plotmultibeam(0.0,0.0,23.413)
#plotmultibeam(0.0,0.0,13.898)
#plotmultibeam(0.0,0.0,13.898)
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2024-7-28 02:37
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社