2014-11-20 119 views
0

我在python 2.7中使用matplotlib。我正在試圖在軸外的圖形區域中創建一個箭頭。在圖形區域繪製帶銳利邊緣的箭頭

from matplotlib.pyplot import * 

fig = figure() 
ax1 = fig.add_axes([.1,.1,.6,.8]) 

ax1.annotate('',xy=(.8,.92),xycoords='figure fraction',xytext=(.8,.1) 
      arrowprops=dict(arrowstyle='->',fc='k',lw=10)) 

ax2 = fig.add_axes([.85,.1,.1,.8]) 
ax2.spines['top'].set_visible(False) 
ax2.spines['bottom'].set_visible(False) 
ax2.spines['left'].set_visible(False) 
ax2.spines['right'].set_visible(False) 
ax2.tick_params(axis='both',which='both', 
       top='off',right='off',left='off',bottom='off', 
       labeltop='off',labelright='off',labelleft='off',labelbottom='off') 

ax2.patch.set_facecolor('None') 

ax2.set_xlim(0,1) 
ax2.set_ylim(0,1) 
ax2.arrow(.5,0,0,1,fc='k',ec='k',head_width=.25, 
      head_length=.05,width=.15,length_includes_head=True)  
show() 

使用

ax1.annotate(...) 

給了我一個 '模糊' 看箭頭。我能弄清楚如何得到一個更好的看箭頭的唯一方法是通過創建另一個軸只是爲了添加箭頭,使用

ax2.arrow(...) 

(網站不會讓我張貼圖片,但複製和粘貼代碼你會看到我在說什麼) 還有一個更好的方式來做到這一點,雖然...

回答

0

我認爲改變箭頭風格將在這裏幫助。例如,將其從'->'更改爲'simple'可以提供更好看的箭頭。您可以通過玩mutation_scale來改變寬度。例如,

ax1.annotate('',xy=(.8,.92),xycoords='figure fraction',xytext=(.8,.1), 
    arrowprops=dict(arrowstyle="simple",fc="k", ec="k",mutation_scale=30)) 

這是你的腳本,上述simple箭頭藍色繪製。請注意與黑色箭頭的區別->箭頭與annotate

from matplotlib.pyplot import * 

fig = figure() 
ax1 = fig.add_axes([.1,.1,.5,.8]) 

# Your original arrow (black) 
ax1.annotate('',xy=(.7,.92),xycoords='figure fraction',xytext=(.7,.1), 
      arrowprops=dict(arrowstyle='->',fc='k',lw=10)) 

# "Simple" arrow (blue) 
ax1.annotate('',xy=(.8,.92),xycoords='figure fraction',xytext=(.8,.1), 
      arrowprops=dict(arrowstyle="simple",fc="b", ec="k",mutation_scale=30)) 

ax2 = fig.add_axes([.85,.1,.1,.8]) 
ax2.spines['top'].set_visible(False) 
ax2.spines['bottom'].set_visible(False) 
ax2.spines['left'].set_visible(False) 
ax2.spines['right'].set_visible(False) 
ax2.tick_params(axis='both',which='both', 
       top='off',right='off',left='off',bottom='off', 
       labeltop='off',labelright='off',labelleft='off',labelbottom='off') 

ax2.patch.set_facecolor('None') 

ax2.set_xlim(0,1) 
ax2.set_ylim(0,1) 
ax2.arrow(.5,0,0,1,fc='r',ec='k',head_width=.25, 
      head_length=.05,width=.15,length_includes_head=True)  
show() 

enter image description here