【发布时间】:2020-09-22 17:53:38
【问题描述】:
我想找到 (eq1, eq2) 和 (eq1, eq3) 之间的交点,并在每个轴上用虚线表示该点。这段代码没有给我确切的观点,而只是一个近似值。我不明白我在哪里做错了。
import matplotlib.pyplot as plt
import numpy as np
f = []
h = []
j = []
point = []
for x in range(25):
eq1 = x * 185 * 3
eq2 = 11930 - (12502 / 6) + (x * 185) / 6
eq3 = 11930 - (12502 / 3) + (x * 185) / 6
point.append(x)
f.append(eq1)
h.append(eq2)
j.append(eq3)
plt.plot(point, f)
plt.plot(point, h)
plt.plot(point, j)
plt.legend(loc='lower right', fontsize=10)
idx1 = np.argwhere(np.diff(np.sign(np.array(f) - np.array(h)))).flatten()
idx2 = idx = np.argwhere(np.diff(np.sign(np.array(f) - np.array(j)))).flatten()
plt.plot(np.array(point)[idx1+1], np.array(h)[idx1+1], 'ro')
plt.plot(np.array(point)[idx2+1], np.array(j)[idx2+1], 'ro')
plt.show()
【问题讨论】:
-
这是MCVE 的完美示例。非常好的问题。继续加油!
标签: python-3.x matplotlib plot intersection