# -*- coding:utf-8 -*-
import numpy
import matplotlib.pyplot as plt
import q30
import q36

def plot_freq_word(freq_word_cnt, top):
    x, y, label = [], [], []
    for (i, (word, cnt)) in enumerate(freq_word_cnt):
        if i >= top:
            break
        x.append(i+1)
        y.append(cnt)
        label.append(word.decode('utf-8'))

    left = numpy.array(x)
    height = numpy.array(y) 
    plt.bar(left, height, align="center")
    plt.xticks(x, label)
    plt.show()

if __name__ == '__main__':
    ma_dic = q30.maResultRead()
    freq_word_cnt = q36.get_word_freq(ma_dic)
    plot_freq_word(freq_word_cnt, 10)
