use*_*632 3 python numpy matplotlib pandas
我想得到的是,(x, y)对于给定的x和y值,y值变得更平滑.
例如,
x = range(10)
y = [0.3, 0.37, 0.41, 0.52, 0.64, 0.68, 0.71, 0.72, 0.73, 0.74]
plt.plot(x, y)
Run Code Online (Sandbox Code Playgroud)
我想获得图表开始变得稳定的红色圆点(或接近点).
我怎样才能做到这一点?
您正在寻找的是更准确的斜率或一阶差分,为了了解曲线开始平滑的位置,您可以计算一阶差分/斜率并找出斜率低于某个阈值的第一个指数:
import matplotlib.pyplot as plt
import numpy as np
x = np.array(range(10))
y = np.array([0.3, 0.37, 0.41, 0.52, 0.64, 0.68, 0.71, 0.72, 0.73, 0.74])
slopes = np.diff(y) / np.diff(x)
idx = np.argmax(slopes < 0.02) # find out the first index where slope is below a threshold
fig, ax = plt.subplots()
ax.plot(x, y)
ax.scatter(x[idx], y[idx], s=200, facecolors='none', edgecolors='r')
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
70 次 |
| 最近记录: |