在条形图上显示值

时间:2020-06-12 17:45:17

标签: python matplotlib bar-chart seaborn catplot

以下代码生成一个pdf文件,该文件由循环barplot在数据帧上馈送。我的目标是在栏上注释值。我已经尝试过多次监视值,但是失败了。我可以在这方面得到任何帮助吗?谢谢

import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
from matplotlib.backends.backend_pdf import PdfPages

d = {'index': ['index1', 'index1', 'index2', 'index2'], 'group': ['gr1', 'gr1','gr2','gr2'],
targetscore':[15,15,10,10], 'exam':['old','new','old','new'], 'score':[5,6,7,8]}
df = pd.DataFrame(data = d)
pp = PdfPages('mypath/extraction.pdf')
for i in range(len(df['group'])):
subdf = df[df['group'] == df.iloc[i,1]]
sns.catplot(y = 'score', x = 'group', data = subdf, hue = 'exam', kind = 'bar', 
        row = 'index', col = 'exam', col_order = ['old', 'new'], height = 3, aspect = 2)
plt.show
pp.savefig(plt.gcf())
pp.close()

0 个答案:

没有答案
相关问题