from matplotlib import pyplot as plt
import numpy as np
def plotBar(num_dict):

    index_list,data = zip(*num_dict)
    fig=plt.figure(1,figsize=(30,25))
    ax1=plt.subplot(111)

    x_bar=np.arange(len(index_list))
    """绘制条形图的主体,条形图实质上就是一系列的矩形元素,我们通过plt.bar函数来绘制条形图"""
    rect=ax1.bar(x=x_bar,height=data,width=0.8,color="lightblue")
    """向各条形上添加数据标签"""
    for rec in rect:
        x=rec.get_x()
        height=rec.get_height()
        ax1.text(x+0.2,1.02*height,str(height),fontsize=20)
    """绘制x,y坐标轴刻度及标签,标题"""
    ax1.set_xticks(x_bar)
    ax1.set_xticklabels(index_list,fontsize=20)
    ax1.set_xlabel("Tag type",fontsize=20)
    ax1.set_ylabel("number",fontsize=20)
    ax1.set_title("The visualization")

    plt.show()
plotBar(tag_num_dict)
02-11 01:46