2024.10.29 使用Matplotlib绘制平滑曲线与极坐标曲线

主页 专辑 程序 博客 关于


'''光的偏振'''
import matplotlib.pyplot as plt
import numpy as np
from scipy import interpolate

#data
x = np.arange(0,370,10)
y = np.array([1.597,1.552,1.412,1.210,0.900,0.680,0.408,0.197,0.051,0.004,
              0.053,0.183,0.388,0.638,0.932,1.187,1.408,1.553,1.596,
              1.541,1.391,1.163,0.907,0.609,0.363,0.163,0.041,0.006,
              0.058,0.205,0.418,0.679,0.961,1.211,1.420,1.553,1.597])

#Cartesian
f = interpolate.interp1d(x, y, kind='cubic')
x_new = np.linspace(0, 360, 36000)

plt.figure("Cartesian")
plt.plot(x, y, 'o')
plt.plot(x_new, f(x_new), '-')
plt.title(r'$i({\theta})$~${\theta}$')
plt.xlabel(r'${\theta}$')
plt.ylabel(r'$i$')
plt.grid(True)

#polar
theta = np.arange(0,2*37*np.pi/36,2*np.pi/36)
g = interpolate.interp1d(theta,y,kind='cubic')
theta_new = np.linspace(0,np.pi*2,36000)

plt.figure("polar")
plt.axes(polar=True)
plt.plot(theta,y,'o')
plt.plot(theta_new, g(theta_new), '-')
plt.title(r'$i({\theta})$~${\theta}$')

#show
plt.legend()
plt.show()
    

Powered by Neocities

To learn more HTML/CSS, check out these tutorials!