2014-09-10 93 views
3

我想制作一个简单的箭头和一个两个头箭头。我用下面做一个简单的箭头,但我怀疑这是最简单的方法:matplotlib简单和两个箭头

import matplotlib.pyplot as plt 
arr_width = .009 # I don't know what unit it is here. 
fig = plt.figure() 
ax1 = fig.add_subplot(111) 
ax1.plot(range(10)) 
ax1.arrow(1, 1, 0, .5, width = arr_width, head_width = 3 * arr_width, 
    head_length = 9 * arr_width) 
plt.show() 

我无法找到如何使这种方法两头箭头。

+0

的代码你没有按供应没有工作。 – Ffisegydd 2014-09-10 09:26:37

回答

5

您可以使用该方法annotate空白文本注释并设置arrowprops字典包括arrowstyle='<->'双箭头,如下图所示:

import matplotlib.pyplot as plt 

plt.annotate(s='', xy=(1,1), xytext=(0,0), arrowprops=dict(arrowstyle='<->')) 

plt.show() 

Example plot

+2

该解决方案提供的箭头略短于所需的箭头。此外,使用arrowstyle ='<->'意味着在注释中不能使用shrink = 0.0。因此,我认为这个问题仍然存在。 – newling 2017-03-05 09:33:57

+0

@newling您可以使用'plt.annotate(s ='',xy =(1,1),xytext =(0,0),arrowprops = dict(arrowstyle ='<->',shrinkA = 0,shrinkB = 0) )'而不是 – Elpy 2017-04-20 16:58:21