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()
python seaborn barplot 标注value
最新推荐文章于 2024-05-28 18:50:13 发布