2014-09-10 98 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