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

2024-05-01

我想更改注释中的箭头头(matplotlib),但与其他属性一起使用时不起作用,例如shrink。通过查看参数集,它似乎改变了创建的对象的类型。


Example

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

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':'->'})

Problem

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

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

为什么它不起作用?

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

相关问题 https://stackoverflow.com/questions/36148773/how-to-change-the-head-size-of-the-double-head-annotate-in-matplotlib


我在用:

蟒蛇:3.4.3 + numpy:1.11.0 + matplotlib:1.5.1


来自matplotlib 文档 http://matplotlib.org/api/text_api.html#matplotlib.text.Annotation,“如果字典有键 arrowstyle,则使用给定字典创建 FancyArrowPatch 实例并绘制。否则,创建并绘制 YAArrow 补丁实例。”

正如您在同一链接中看到的,shrink是一个有效的密钥YAArrow但不是为了FancyArrowPatch.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何更改matplotlib注释中的箭头样式? 的相关文章

随机推荐