橢圓方程詳細請參考: wiki
上代碼:
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.font_manager import FontProperties
#設置中文字體
myfont = FontProperties(fname='C:/Windows/Fonts/msyh.ttc')
theta=np.arange(0,2*np.pi,0.02)
plt.subplot(111, polar=True, resolution=1)
# 這里的橢圓中心在原點, 短半軸3, 長半軸5
plt.plot(theta,3/np.sqrt(1-0.8**2*np.cos(theta+np.pi)**2),'b',lw=1,label=u'橢圓')
plt.plot(theta,9/(1-0.8**2*np.cos(theta+np.pi)**2),'--g',lw=2, label=u'橢圓平方')
x = 5*np.cos(theta); y = 3*np.sin(theta)
plt.plot(theta,(x**2+y**2),'r--',lw=2, label=u'橢圓偏光光強')
#plt.plot(np.arctan2(y,x),np.sqrt(x**2+y**2),'b.-',lw=1) #橢圓
#plt.plot(np.arctan2(y,x),x**2+y**2,'b.-',lw=1) #橢圓偏光光強
plt.rgrids(np.arange(5,30,5),angle=45)
#plt.thetagrids([0,45,90])
plt.legend(bbox_to_anchor=(0.02, 0.95), loc=2, prop=myfont)
plt.show()
之所以橢圓偏光光強曲線與橢圓平方曲線沒能重合, 是因為光強的方程采用的是直角坐標, 所以這里畫在極坐標系中并不合適, 只是為了對比說明問題罷了!