问题描述
是否可以外推我的绘图图以获得 Y 轴截距?
这是我的代码,我使用了 Plotly express,但也可以使用其他类型:
import pandas as pd
import numpy as np
import plotly.express as px
a = np.array([[0.5,1,2,3,5,7],[68,54,30,18.5,6,1.8]])
a = pd.DataFrame(a.T,columns = ["t","c"])
a.set_index("t")
fig = px.scatter(a,x= a["t"],y=a["c"],log_y=True)
fig.update_traces(mode="lines+markers")
fig.show()
解决方法
您可以使用 scipy.stats 进行线性回归! https://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.stats.linregress.html
这也返回截距。
编辑:我没有看到您的 y 轴是非线性的。既然您知道如何使数据线性化,只需在拟合后还原截距即可。