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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值