简体   繁体   English

非线性回归散点图

[英]non linear regression scatter plot

My data points are:我的数据点是:

x =[5.00E-07, 1.40E-06, 4.10E-06, 1.25E-05, 3.70E-05, 1.11E-04, 0.33E-04, 1.00E-03] x =[5.00E-07, 1.40E-06, 4.10E-06, 1.25E-05, 3.70E-05, 1.11E-04, 0.33E-04, 1.00E-03]
y= [494.55, 333.4666667, 333.3333333, 333.1, 303.4966667, 197.7533333, 66.43333333, 67.715] y= [494.55, 333.4666667, 333.3333333, 333.1, 303.4966667, 197.7533333, 66.43333333, 67.715]

The x axis on my plot must be exponential!!我的图上的 x 轴必须是指数的!!

I want to make a regression line such as the image added, in an S shape.我想以 S 形制作一条回归线,例如添加的图像。 How do I do this (in matlab or python)?我该怎么做(在 matlab 或 python 中)? IMG UPDATE: I tried: IMG更新:我试过:

import matplotlib.pyplot as plt     
from scipy.interpolate import make_interp_spline     
import numpy as np     

#create data     
x = np.array([5.00E-07, 1.40E-06, 4.10E-06, 1.25E-05, 3.70E-05, 1.11E-04, 3.33E-04, 1.00E-03])     
y= np.array([494.55, 333.4666667, 333.3333333, 333.1, 303.4966667, 197.7533333, 66.43333333, 67.715])     

#define x as 200 equally spaced values between the min and max of original x     
xnew = np.linspace(x.min(), x.max(), 100)     

#define spline      
spl = make_interp_spline(x, y, k=2)     
y_smooth = spl(xnew)    

#create smooth line chart     
plt.plot(x,y, 'o', xnew, y_smooth)    
plt.xscale("log")    
plt.show()    

My results are: results How can I make it even smoother?我的结果是:结果我怎样才能让它更顺畅? differing the k doesn't make it better.不同的 k 并没有使它更好。

Note that the higher the degree you use for the k argument, the more “wiggly” the curve will be请注意,用于 k 参数的度数越高,曲线就越“摆动”

Depending on how curved you want the line to be, you can modify the value for k.根据您希望线条的弯曲程度,您可以修改 k 的值。

try this:尝试这个:

import matplotlib.pyplot as plt
from scipy.interpolate import make_interp_spline
import numpy as np

#create data
x = np.array([5.00E-07, 1.40E-06, 4.10E-06, 1.25E-05, 3.70E-05, 1.11E-04, 3.33E-04, 1.00E-03])
y= np.array([494.55, 333.4666667, 333.3333333, 333.1, 303.4966667, 197.7533333, 66.43333333, 67.715])

#define x as 200 equally spaced values between the min and max of original x 
xnew = np.linspace(x.min(), x.max(), 200) 

#define spline
spl = make_interp_spline(x, y, k=3)
y_smooth = spl(xnew)

#create smooth line chart 
plt.plot(xnew, y_smooth)
plt.show()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM