Lui*_*uis 5 python numpy matplotlib
我想更改注释 ( ) 中的箭头头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':'->'})
Run Code Online (Sandbox Code Playgroud)
问题
我尝试将箭头类型与第一个注释中的其他属性一起设置,如下所示:
ax.annotate( 'other\nmax', xy=(np.pi*5/2, 1), xytext=(7,1.5), ha='center', \
arrowprops={'arrowstyle':'->', 'shrink':0.05})
Run Code Online (Sandbox Code Playgroud)
但是,该行会引发错误:
AttributeError: Unknown property shrink
Run Code Online (Sandbox Code Playgroud)
为什么它不起作用?
如何更改注释的箭头样式?
我在用:
蟒蛇:3.4.3 + numpy:1.11.0 + matplotlib:1.5.1
从matplotlib 文档中,“如果字典具有键 arrowstyle,则使用给定字典创建 FancyArrowPatch 实例并绘制。否则,创建并绘制 YAArrow 补丁实例。”
正如您在同一链接中看到的,shrink是 的有效密钥YAArrow,但不适用于FancyArrowPatch。
| 归档时间: |
|
| 查看次数: |
5445 次 |
| 最近记录: |