Python使用matplotlib,numpy,scipy進行散點的平滑曲線化方法

首先給出一個沒有smooth過的曲線

import matplotlib.pyplot as plt
import numpy as np
 
T = np.array([6, 7, 8, 9, 10, 11, 12])
power = np.array([1.53E+03, 5.92E+02, 2.04E+02, 7.24E+01, 2.72E+01, 1.10E+01, 4.70E+00])
 
plt.plot(T,power)
plt.show()

輸出的曲線如下圖

使用scipy庫可以進行曲線的smooth

代碼如下

import matplotlib.pyplot as plt
import numpy as np
from scipy.interpolate import spline
 
T = np.array([6, 7, 8, 9, 10, 11, 12])
power = np.array([1.53E+03, 5.92E+02, 2.04E+02, 7.24E+01, 2.72E+01, 1.10E+01, 4.70E+00])
xnew = np.linspace(T.min(),T.max(),300) #300 represents number of points to make between T.min and T.max
 
power_smooth = spline(T,power,xnew)
 
plt.plot(xnew,power_smooth)
plt.show()

輸出的圖片爲

轉載自:https://blog.csdn.net/cdqn10086/article/details/70143616

import matplotlib.pyplot as plt
import numpy as np
from scipy.interpolate import spline
 
T = np.array([6, 7, 8, 9, 10, 11, 12])
power = np.array([1.53E+03, 5.92E+02, 2.04E+02, 7.24E+01, 2.72E+01, 1.10E+01, 4.70E+00])
xnew = np.linspace(T.min(),T.max(),300) #300 represents number of points to make between T.min and T.max
 
power_smooth = spline(T,power,xnew)
 
plt.plot(xnew,power_smooth)
plt.show()

 

Interpolation (scipy.interpolate)

https://docs.scipy.org/doc/scipy/reference/tutorial/interpolate.html

 

Python/Matplotlib光滑曲線畫圖---Scipy庫函數使用

https://blog.csdn.net/gsww404/article/details/77916986

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章