matplotlib 注释中的箭头属性
Arrow properties in matplotlib annotate
我有 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()
给出这个数字:
这有帮助吗?
我有 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()
给出这个数字:
这有帮助吗?