Python使用matplotlib,numpy,scipy进行散点的平滑曲线化方法

来源:互联网 发布:软件网络请求超时 编辑:程序博客网 时间:2024/05/29 13:40

首先给出一个没有smooth过的曲线

import matplotlib.pyplot as pltimport numpy as npT = 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 pltimport numpy as npfrom scipy.interpolate import splineT = 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.maxpower_smooth = spline(T,power,xnew)plt.plot(xnew,power_smooth)plt.show()

输出的图片为


2 0
原创粉丝点击