2013-10-08 5 views
3

나는이처럼 보이는 그림 만들기 위해 노력하고 있습니다 :matplotlib imshow 맵에 화살표 * 및 * 텍스트를 사용하여 주석을 달 수 있습니까?

better image

을하지만 그 대신 내가 얻을이 :

from pylab import * 
from matplotlib import colors 
# A = [[1,2,3,4,5]] 
A = [[0],[1]] 
Amap = colors.ListedColormap(['blue','green']) 

figure(1) 
imshow(A, cmap=Amap, interpolation='nearest') 
annotate('AA BB',xy=(0,0), xytext=(.8,0), fontsize=20) 
axis('off') 
savefig('graph-py.pdf') 
show() 

: 여기

basic image

내 프로그램입니다 나는 화살을 얻기 위해 모든 노력을 기울 였지만 그렇게 할 수는없는 것 같습니다. 어떤 아이디어?

답변

7

나는 보통 내가하고 싶은 것을 찾아 내기 위해 gallery을 조사한다. annotation_demo2는 당신이 원했던 것과 비슷하게 보입니다 ... 나는 이것을 생각해 냈습니다. 당신이 arrowprops kwarg을 놓친 것처럼 보입니다.

from pylab import * 
from matplotlib import colors 
# A = [[1,2,3,4,5]] 
A = [[0],[1]] 
Amap = colors.ListedColormap(['blue','green']) 

fig = figure(1) 
ax = fig.add_subplot(111, autoscale_on=False) 
imshow(A, cmap=Amap, interpolation='nearest') 
ax.annotate('AA BB', fontsize=20, xy=(.25, .75), 
      xycoords='data', xytext=(150, -6), 
      textcoords='offset points', 
      arrowprops=dict(arrowstyle="->", 
          linewidth = 5., 
          color = 'red') 
      ) 
ax.annotate('CC DD', fontsize=20, xy=(.25, .25), 
      xycoords='data', xytext=(150, -6), 
      textcoords='offset points', 
      arrowprops=dict(width = 5., 
          headwidth = 15., 
          frac = 0.2, 
          shrink = 0.05, 
          linewidth = 2, 
          color = 'red') 
      ) 
axis('off') 
savefig('graph-py.pdf') 
show() 
close() 

은 다음과 같습니다

annotate example

+0

감사합니다! 나는 갤러리를 들여다보고 작동시킬 수 없었다. 다행히 내 벌레를 찾았 어! – vy32

+0

나는 YAArow 패치가 FancyArrowPatch보다 더 좋다고 생각한다. – wwii