该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))
Run Code Online (Sandbox Code Playgroud)
该代码也适用于没有指定宽度的双面箭头:
plt.annotate('', xy=(3.2, 0), xycoords='data',
xytext=(5.9, 0), textcoords='data',
arrowprops=dict(facecolor='black', arrowstyle='<->'))
Run Code Online (Sandbox Code Playgroud)
但是对于具有宽度的双箭头:
plt.annotate('', xy=(3.2, 0), xycoords='data',
xytext=(5.9, 0), textcoords='data',
arrowprops=dict(facecolor='black', width=3, arrowstyle='<->'))
Run Code Online (Sandbox Code Playgroud)
导致 matplotlib 错误:“AttributeError: Unknown property width”
小智 8
尝试这个:
arrowprops=dict(facecolor='black', lw=3, arrowstyle='<->')
Run Code Online (Sandbox Code Playgroud)