matplotlib 如何在特定的地方制作箭头

qlckcl4x  于 2023-10-24  发布在  其他
关注(0)|答案(2)|浏览(148)

你好,我有这样的代码:

from matplotlib import pyplot as plt

b = 2.8977685 * (10 ** -3)

k_range = [i for i in range(3500, 5500)]
results = [b/i for i in range(3500, 5500)]

plt.plot(results, k_range)
plt.show()

现在我如何画arron来找到K = 4800的结果

xn1cxnb4

xn1cxnb41#

IIUC,像这样的东西?

from matplotlib import pyplot as plt
import numpy as np

b = 2.8977685 * (10 ** -3)

k_range = [i for i in range(3500, 5500)]
results = [b/i for i in range(3500, 5500)]

k = np.array(k_range)
i = np.where(k==4800)

r=np.array(results)
r[i]

plt.plot(results, k_range, marker='x', markevery=[i[0][0]], markeredgecolor='r')
ax = plt.gcf().gca()
ax.annotate("", xy=(r[i], 4800), xytext=(r[i], 4400), arrowprops=dict(arrowstyle="->"))
plt.show()

输出量:

brvekthn

brvekthn2#

使用matplotlib.pyplot.arrow()

from matplotlib import pyplot as plt

b = 2.8977685 * (10 ** -3)

k_range = [i for i in range(3500, 5500)]
results = [b/i for i in range(3500, 5500)]

plt.plot(results, k_range)
plt.arrow(6E-7, 4000, 8E-8, 200, ec='red', width = 5E-12, head_width=1E-8)
plt.show()

相关问题