Python 线性插值,已知x求Y
import numpy as np import matplotlib.pyplot as plt y = np.array([0, 38.39, 71.41, 99.66, 123.67, 143.88, 160.61, 174.03, 184.16, 190.8, 193.52]) x = np.array([0, 0.37, 0.74, 1.11, 1.48, 1.85, 2.22, 2.59, 2.96, 3.33, 3.7]) plt.plot(x, y, '-') y_val = 30 root = np.interp(y_val, y, x) print(root) plt.plot(root, y_val, marker="X") plt.plot([root, root, 0], [0, y_val, y_val], "--") plt.xlim(0, None) plt.ylim(0, None) plt.show()
浙公网安备 33010602011771号