簡體   English   中英

Python:如何在圖表中獲得更平滑的起點?

[英]Python: how can I get the smoother-starting-point in graph?

我想得到的是點, (x, y) ,其中y值對於給定的x和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)

在此輸入圖像描述

我想獲得圖表開始變得穩定的紅色圓點(或接近點)。

我怎樣才能做到這一點?

在此輸入圖像描述

您正在尋找的是更准確的斜率或一階差分,為了了解曲線開始平滑的位置,您可以計算一階差分/斜率並找出斜率低於某個閾值的第一個指數:

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

在此輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM