What I want to get is the point, (x, y)
, where the y value getting smoother for given x and y values.
For example,
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)
I want to get the red-circle point (or near point) where the graph starts getting stable.
How can I do this?
What you are looking for is slope or first order difference more exactly, to get an idea where the curve starts to smooth out, you can calculate the first order difference / slope and find out the first index where the slope is below a certain threshold:
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')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.