2014-02-24 1 views
0

yahoo finance과 마찬가지로 사전에 키와 값을 차트 위에 표시하고자합니다. 날짜 가격과 시간 이후에는 따옴표를 사용하십시오.matplotlib/python에서 차트 위의 단일 변수 표시

예 사전 :

d = {'key1':'value1', 'key2':'value2','key3':'value3','key4':'value4'} 

어떻게 matplotlib pltpython를 사용하여 차트 위의 사전에있는 모든 키와 값을 표시 할 수 있습니까?

+0

"위의 차트"는 무엇을 의미합니까? 제목에? 제발 좀 더 구체적으로. – Christian

+0

@Christian이 그것을 편집 할 것입니다 – pyCthon

+0

[도움이 될 것입니다] (http://matplotlib.org/users/text_intro.html#basic-text-commands), 아마도'annotate' 또는'figtext'를 사용하십시오. – Christian

답변

1

자동 레이블과 같은 기능을 사용하십시오. 이 예제는 각 막대 요소 위의 값을 막 대형 차트에 배치합니다. api example code: barchart_demo.py

def autolabel(self,ax, mybar): 
''' 
Label each bar with the particular value 

@parameter ax - The subplot being processed 
@parameter mybar - The bars in the graph that must be labeled 
''' 

for rect in mybar: 
    # Determine the actual height 
    height = rect.get_height() 
    pos = rect.get_x() + rect.get_width()/2. 
    ax.text(pos, 1.05*height, '%d'%int(height), ha='center', va='bottom', \ 
      rotation='vertical', color='r') 
return 
+0

이것은 막대 위에 직접 인쇄하지만 실제 차트 위에는 인쇄하지 않습니다. 그러나 위에서 언급 한 Christian 기능과 함께 살펴 보는 것은 시작 지점입니다 – pyCthon

+0

예제 코드는 범례를 차트에 추가하는 방법도 설명합니다. 당신도 그것을 시험해 볼 수 있습니다. – sabbahillel