如何在matplotlib中的范围之间绘制数据?

问题描述

我使用 curve_fit 函数为数据拟合了一条曲线,但只需要 2 个点之间的拟合曲线。我的意思不是更改轴长度,而是更改绘制数据的范围。例如在下图中,我只需要在 x=9 和 x=11 之间绘制蓝线。我该怎么做?

enter image description here

我已经得到的代码

#plotting data
plt.plot(kcoord,data[4],'k',alpha=0.25)

#column 5
y2=data[4]
x2=kcoord
# get indices of elements in desired range
idx2 = np.argwhere((9 < x2) & (x2 < 11))
# get y-values in desired range
selection2 = y2[idx2]
xshort2=x2[idx2]
plt.plot(xshort2,selection2)


#column 5 curvefitting
init_guess2=np.array([-0.31934191,6.23228567,-31.04172149])
popt2,pcov2 = curve_fit(func,xshort2.ravel(),selection2.ravel(),init_guess2)
plt.plot(x2,func(x2,*popt2),label="quadratic fit",color='blue')
print(popt2)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)