【发布时间】:2020-03-23 16:37:15
【问题描述】:
我有以下数据框:
my_df = pd.DataFrame(data={'Year': ['2017','2018','2019','2019','2019','2019','2020','2020'],
'Threshold':[96, 91, 20.59, 47.37, 78.12, 10.00, 15.00 ,91],
'Fee' : ["No","No", "20%", "20%", "5%", "20%", "20%", "No"]})
我正在使用 seaborn 来绘制它:
palette={"No": "g","20%": "y", "5%": "r"}
fig,ax = plt.subplots()
fig.set_size_inches(10,8)
sns.barplot(x="Year", y="Threshold",hue = 'Fee', palette = palette, data=my_df, ci=None)
for p in ax.patches:
ax.annotate("%.2f" % p.get_height(), (p.get_x() + p.get_width() / 2, p.get_height()),
ha='center', va='center', fontsize=11, color='black', xytext=(0, 10),
textcoords='offset points',fontweight='bold')
但是,显示的图表返回每年阈值变量的平均值,我想在图表上显示所有 8 个数据帧阈值。
我该如何解决?
【问题讨论】:
标签: python plot bar-chart seaborn color-palette