我有個數據點的兩個列表:平滑曲線在Python
list_x = [-10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49]
list_y = [1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
當我繪製出來,圖形看起來就像這樣:基於這些
import matplotlib.pyplot as plt
plt.plot(list_x, list_y)
plt.show()
數據點,有沒有辦法使圖形看起來像下面的圖形並得到它的圖形方程?
========================================= ==================
我已經嘗試使用here的解決方案,它會產生一個不平滑的圖形。
from scipy.interpolate import spline
import numpy as np
list_x_new = np.linspace(min(list_x), max(list_x), 1000)
list_y_smooth = spline(list_x, list_y, list_x_new)
plt.plot(list_x_new, list_y_smooth)
plt.show()
的可能的複製[繪製與PyPlot平滑線(https://stackoverflow.com/questions/5283649/plot-smooth-line-with-pyplot) –