我有以下几点:
[[1,10],[2,5.49],[3,0.89],[4,-0.14],[5,-1.07],[6,0.84]]我计算了通过这些点y=0.83535714x^2-7.74778571x+17.116的抛物线。值:
> print(matrix)
[[ 0.83535714]
[-7.74778571]
[17.116 ]]此外,我还拆分了以下几个点:
points = np.asarray([[1,10],[2,5.49],[3,0.89],[4,-0.14],[5,-1.07],[6,0.84]])
points_x_axis = points[:, 0]
points_y_axis = points[:, 1]现在我想画抛物线和点。我该怎么做呢?
发布于 2021-11-15 13:46:51
使用多项式回归来平滑图形
import numpy as np
import matplotlib.pyplot as plt
def parabola(x):
return 0.83535714*x**2-7.74778571*x+17.116
x = np.linspace(0, 9, 100)
y = parabola(x)
plt.plot(x, y)
plt.scatter(points_x_axis, points_y_axis)
plt.show()

#Simple plotting
import matplotlib.pyplot as plt
plt.plot(points_x_axis, points_y_axis, 'o')
plt.plot(points_x_axis, 0.83535714*points_x_axis**2-7.74778571*points_x_axis+17.116)
plt.show()输出:

发布于 2021-11-15 14:44:26
使用np.polyfit和np.polyval
data = np.array([[1,10],[2,5.49],[3,0.89],[4,-0.14],[5,-1.07],[6,0.84]])
p = np.polyfit(data[:, 0], data[:, 1], 2)
x = np.linspace(0, 9, 100)
y = np.polyval(p, x)
plt.plot(x, y)
plt.plot(data[:, 0], data[:, 1], 'k.')https://stackoverflow.com/questions/69975340
复制相似问题