gpt4 book ai didi

python - 对数对数图中的 Matplotlib 箭头

转载 作者:太空狗 更新时间:2023-10-30 02:38:43 26 4
gpt4 key购买 nike

我正在尝试使用 matplotlib 在对数对数图中画一个箭头,它看起来像这样:

enter image description here

我知道有人建议关闭轴 ( Matplotlib: Draw a vertical arrow in a log-log plot ),但我确实需要轴。此外,该建议似乎没有任何改变(除了按预期关闭坐标轴之外):

plt.figure();plt.loglog([1,10,60],[1,0.1,0.005])
plt.axis('off')
plt.arrow(2,0.002,5,0.098,'k',head_length=0.3)

到目前为止,我的工作是使用线性轴环境创建一个不可见的插图(意思是:轴关闭)并在插图中绘制箭头,这可行但确实有点令人不快。有更简单的方法吗?或者人们是否建议使用例如添加这些类型的附加功能。 inkscape,主要情节完成后?

最佳答案

您可以使用 plt.annotate而不是 plt.arrow。这在 documentation for plt.arrow 中有说明。 :

The resulting arrow is affected by the axes aspect ratio and limits. This may produce an arrow whose head is not square with its stem. To create an arrow whose head is square with its stem, use annotate()

例如:

import matplotlib.pyplot as plt

plt.figure()
plt.loglog([1,10,60],[1,0.1,0.005])
plt.annotate('', xy=(5, 0.098), xytext=(2, 0.002),
arrowprops=dict(facecolor='black', shrink=0.),
)

plt.ylim(0.001, 10)

plt.show()

enter image description here

请注意,您可能需要调整轴限制以使箭头适合绘图。在这里,我必须更改 ylim

关于python - 对数对数图中的 Matplotlib 箭头,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46139945/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com