如何在Matplotlib注释中更改箭头样式?

5

我想要更改注释(matplotlib)中箭头的头部,但是当与其他属性一起使用时,例如 shrink,它似乎无法正常工作。通过查看设置的参数,似乎更改了所创建对象的类型。


示例

以下代码显示了两种类型的注释箭头。

import matplotlib.pyplot as plt

import numpy as np

xx = np.linspace(0,8)
yy = np.sin(xx)
fig, ax = plt.subplots(1,1, figsize=(8,5))
ax.plot(xx,yy)
ax.set_ylim([-2,2])

ax.annotate( 'local\nmax', xy=(np.pi/2, 1), xytext=(1,1.5), ha='center', \
            arrowprops={'shrink':0.05})
ax.annotate( 'local\nmin', xy=(np.pi*3/2, -1), xytext=(5,0), ha='center', \
            arrowprops={'arrowstyle':'->'})

在这里输入图片描述


问题

我尝试将箭头类型与第一个注释中的其他属性一起设置,如下所示:

ax.annotate( 'other\nmax', xy=(np.pi*5/2, 1), xytext=(7,1.5), ha='center', \
            arrowprops={'arrowstyle':'->', 'shrink':0.05}) 

然而,这行代码会抛出一个错误:
AttributeError: Unknown property shrink

为什么它不起作用?

如何更改注释的箭头样式?

相关问题


我正在使用:

python: 3.4.3 + numpy: 1.11.0 + matplotlib: 1.5.1

1个回答

0

根据matplotlib文档,"如果字典中有箭头样式键,则创建一个具有给定字典的FancyArrowPatch实例并绘制。否则,创建并绘制YAArrow补丁实例。"

正如您在同一链接中所看到的,shrinkYAArrow的有效键,但不适用于FancyArrowPatch


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接