matplotlib Demo

时间:2019-09-23
本文章向大家介绍matplotlib Demo,主要包括matplotlib Demo使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。
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)

原文地址:https://www.cnblogs.com/rise0111/p/11573550.html