2014-12-05 4 views
0

저는 matplotlib을 사용하여 화살표가있는 주석을 만듭니다. 동일한 머리 길이의 파이썬 주석 화살표

from matplotlib import pyplot as plt 
plt.figure() 
plt.annotate('Text1', xy=(1, 0), xytext=(1, 1), arrowprops=dict(alpha=0.5, fc='r', ec='r', headwidth=10)) 
plt.annotate('Text2', xy=(3, 0), xytext=(3, 3), arrowprops=dict(alpha=0.5, fc='r', ec='r', headwidth=10)) 
plt.annotate('Text3', xy=(6, 0), xytext=(6, 6), arrowprops=dict(alpha=0.5, fc='r', ec='r', headwidth=10)) 
plt.annotate('Text4', xy=(9, 0), xytext=(9, 9), arrowprops=dict(alpha=0.5, fc='r', ec='r', headwidth=10)) 
plt.xlim((0, 10)) 
plt.ylim(0, 10) 
plt.show() 

enter image description here

알 수있는 바와 같이

는, 화살표 머리의 길이가 라인의 길이에 의해 영향을 화살표 사이에서 변화된다.

다른 선 길이이지만 같은 화살촉 길이의 화살표를 만드는 방법을 찾고 있습니다. 많은 옵션이 주석 매뉴얼 페이지에 나열되어 있지만 원하는 결과를 얻을 수 없었습니다.

대체 접근법으로 나는 plt.arrow을 사용하여 화살표를 플로팅하려했습니다. 이 경우 화살표 머리는 원하는대로 보였지만 투명도를 사용하면 추가 선이 보입니다.

최고, 안부에서 zinjaai

답변

1

arrowprops 당신은 머리의 길이를 지정할 수 있지만 frac 아규먼트가 분수 화살표 길이로 머리의 길이를 지정합니다. xyxytext을 알고 있으므로 원하는 머리 길이에 필요한 분수를 계산할 수 있습니다.

제공하신 예 (머리 길이가 0.5 인 경우)를 위해 신속하게 처리하지 못했습니다.

from matplotlib import pyplot as plt 
plt.figure() 
plt.annotate('Text1', xy=(1, 0), xytext=(1, 1), 
     arrowprops=dict(alpha=0.5, fc='r', ec='r', headwidth=10, frac=0.5/1)) 
plt.annotate('Text2', xy=(3, 0), xytext=(3, 3), 
     arrowprops=dict(alpha=0.5, fc='r', ec='r', headwidth=10, frac=0.5/3)) 
plt.annotate('Text3', xy=(6, 0), xytext=(6, 6), 
     arrowprops=dict(alpha=0.5, fc='r', ec='r', headwidth=10, frac=0.5/6)) 
plt.annotate('Text4', xy=(9, 0), xytext=(9, 9), 
     arrowprops=dict(alpha=0.5, fc='r', ec='r', headwidth=10, frac=0.5/9)) 
plt.xlim((0, 10)) 
plt.ylim(0, 10) 
plt.show() 

결과 :

enter image description here

하면 화살표의 길이를 계산하는 기능이 포장 수 (xyxytext 부여) 및 그상의 plt.annotate에 전달한다.

관련 문제