增加matplotlib注释双面箭头的厚度

时间:2017-12-19 20:46:20

标签: matplotlib

width参数适用于单面箭头但使用双面箭头时出错。

import numpy as np
import matplotlib.pyplot as plt

x = np.linspace(0, 10, 1000)
plt.plot(x, np.sin(x));
plt.annotate('', xy=(3.2, 0), xycoords='data',
             xytext=(5.9, 0), textcoords='data',
             arrowprops=dict(facecolor='black', width=3))

这很好,导致这个情节: enter image description here

该代码也适用于未指定宽度的双向箭头:

plt.annotate('', xy=(3.2, 0), xycoords='data',
             xytext=(5.9, 0), textcoords='data',
             arrowprops=dict(facecolor='black', arrowstyle='<->'))

enter image description here

但对于宽度为的双箭头:

plt.annotate('', xy=(3.2, 0), xycoords='data',
             xytext=(5.9, 0), textcoords='data',
             arrowprops=dict(facecolor='black', width=3, arrowstyle='<->'))

导致matplotlib错误:&#34;属性错误:未知属性宽度&#34;

1 个答案:

答案 0 :(得分:1)

尝试一下:

arrowprops=dict(facecolor='black', lw=3, arrowstyle='<->')