gpt4 book ai didi

python - matplotlib 注释中的箭头属性

转载 作者:太空宇宙 更新时间:2023-11-03 13:32:34 30 4
gpt4 key购买 nike

我有 Matplotlib 1.5.1 版,我面临一个有趣的问题。我想在我的情节中添加一个箭头,它的每一端都有头并指定颜色和宽度。然而,研究 Matplotlib documentation on this matter ,我意识到我可能不能同时拥有两者。我可以有一个朝向两端的箭头,但这个箭头将具有默认颜色和线宽 - 如果我在我的 arrowprops 中包含 arrowstyle,这是一个选项,或者我可以省略arrowstyle 并在箭头属性中设置颜色和宽度,但我只有默认箭头。 有没有办法同时获得两者?

我有这个代码:

plt.annotate('', xy=(p[0][0]-p[0][2], 0), xycoords='data', xytext=(p[0][0], 0), textcoords='data', arrowprops=dict(arrowstyle: '<|-|>',color='k',lw=2.5))

这会导致 SyntaxError: invalid syntax

(注意:p 只是一个列表列表,我从中获取我的 x 和 y 值,我正在循环绘制)

最佳答案

您应该能够使用 arrowprops 来设置颜色、宽度和其他属性。

import matplotlib.pyplot as plt

fig = plt.figure()
ax = fig.add_subplot(111)

ax.annotate('test', xy=(0.9, 0.9),
xycoords='data',
xytext=(0, 0),
textcoords='data',
arrowprops=dict(arrowstyle= '<|-|>',
color='blue',
lw=3.5,
ls='--')
)

ax.set_xlim(-0.1,1)
ax.set_ylim(-0.1,1)
fig.show()

给出这个数字:enter image description here

这有帮助吗?

关于python - matplotlib 注释中的箭头属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44489900/

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