2014-04-15 2 views
0

모든 의견에서 사용 된 상위 10 개 단어를 반환하는 reddit 봇의 데이터를 표시하는 matplotlib를 사용하여 기본 막대 그래프를 만들려고합니다. y 축은 사용 된 횟수이고 x 축은 단어입니다. 그러나, 나는 완전한 멍청한 놈이다. 그리고 나는 이것을 계산하는 데 어려움을 겪고있다.matplotlib로 간단한 막대 그래프 만들기?

자세한 내용은 다음과 같습니다. 그래프를 생성하는 함수는 {word} {number of times of} 형식의 사전을 사용합니다. 어떤 도움이라도 대단히 감사 할 것입니다.

편집 :이

def graph_data(self, data): 
    words = [] 
    occurence = [] 

    for k,v in data.items(): 
     words.append(k) 
     occurence.append(v) 

    s = sum(occurence) 
    N = 10 # scale. 
    ind = np.arange(N) 
    width = 0.35 
    fig, ax = plt.subplots() 

    g = ax.bar(ind, occurence, width, color='r') 

    ax.set_ylabel('Occurences') 
    ax.set_title('Words') 
    ax.set_xticks(ind+width) 
    ax.set_xticklabels(words) 

    plt.show() 
+1

를 추가 있어요? 이 데모를보십시오 : http://matplotlib.org/examples/api/barchart_demo.html –

+0

많은 예제가 있습니다 : http://matplotlib.org/1.3.1/examples/ 그들 중 일부 시도하십시오 – bosnjak

+0

이봐, 추가했다. 편집. 데모를 사용하여 썼습니다. 그러나이 오류가 발생합니다. 호환되지 않는 크기 : 인수 '높이'길이 13 또는 스칼라합니다. – user3534148

답변

0

시도는 지금까지 시도 무엇 제한

def graph_data(self, data): 
    words = [] 
    occurence = [] 

    for k,v in data.items(): 
     words.append(k) 
     occurence.append(v) 

    s = sum(occurence) 
    N = 10 # scale. 
    ind = np.arange(N) 
    width = 0.35 
fig=plt.figure(v,k) 
ax=plt.axes(xlim=(0,10),ylim=(1,5)) 
line,=ax.plot([],[],lw=2) 
def init(): 
    line.set_data([],[]) 
    return line, 


def animate(i): 

    #print x 
    line.set_data(set,beds[i]) 
    return line, 




plt.show() 
관련 문제