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

xmjla07d  于 2021-07-13  发布在  Java
关注(0)|答案(0)|浏览(259)

我用曲线拟合函数将曲线拟合成数据,但只需要拟合两点之间的曲线。我的意思不是改变轴的长度,而是改变绘制数据的范围。例如,在下图中,我只需要在x=9和x=11之间绘制蓝线。我该怎么做?

我已经得到的代码是:


# 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)

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题