如何找到绘图线上的最小点 (xmin, ymin) 并在图上添加最小点?
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(-5, 5, 100)
y = x*x - 2*x + 23
# Plot
plt.plot(x, y)
# Plot title
plt.title("\nQuadratic Function: y=x*x - 5*x + 23\n", fontsize=16, weight="bold", color = "red")
# Axis Labels (Asiu pavadinimai)
plt.xlabel("X", fontsize = 10, weight="bold", color="red")
plt.ylabel("Y", fontsize = 10, weight="bold", color="red")
# Add minimum point: To Do
# ?
# Grid
plt.grid()
# Display plot
plt.show()
我找不到最小值。如何添加最低点
使用
np.argmin(y)
找到最小值的索引。使用索引获取该点的 x 和 y 坐标。然后调用您喜欢的任何 matplolib 函数来绘制它。