python seaborn barplot 标注value

import sys
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
import numpy as np

def show_value_for_barplot(barplot, h_v="v", classNum = 3):
    i = 0
    for p in barplot.patches:
        if h_v == "v":
            barplot.annotate(format(int(p.get_height()), 'd'), (p.get_x() + p.get_width() / 2., p.get_height()), \
                             ha = 'center', va = 'center', xytext = (0, 5), textcoords = 'offset points')
            if i < len(barplot.patches) :
                barplot.annotate(str(format(float(data["polyganNumber"].iloc[i]),".2g"))+" faces", (p.get_x() + p.get_width() / 2., 0), \
                                 ha = 'center', va = 'center', fontsize=8, xytext = (25, -25), textcoords = 'offset points')
        elif h_v == "h":
            barplot.annotate(format(int(p.get_width()), 'd'), (p.get_width(), p.get_y()+ p.get_height() / 2.), \
                             ha = 'center', va = 'center', xytext = (30, 0), textcoords = 'offset points')
            if i < len(barplot.patches) :
                barplot.annotate(str(format(float(data["polyganNumber"].iloc[i]),".2g"))+" faces", (0, p.get_y()+ p.get_height() / 2.), \
                                 ha = 'left', va = 'center', fontsize=8, xytext = (-80, 0), textcoords = 'offset points')
        i=i+classNum

filename=sys.argv[1]
data=pd.read_csv(filename)
data.sort_values("polyganNumber",inplace=True)
plt.figure(figsize=(18,9))
fig=sns.barplot(x="fileName",y="runTime",data=data,hue="renderMethod",hue_order=["ScanLineZBuffer","HieraZBuffer","OctreeHieraZBuffer"])
show_value_for_barplot(fig,h_v="v")
plt.xlabel("")
plt.show()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值