此代码为我提供了条形图,但我也想插入百分比,我将如何处理?
Hipertension_factor = appointments.groupby(['No-show'])['Hipertension'].count()
Hipertension_factor.plot(kind = 'bar', title = 'Hipertension')
plt.xlabel('No-show', fontsize = 18)
plt.ylabel('Hipertension', fontsize = 18)
答案 0 :(得分:0)
我们无法提供代码来解决您的问题,但是有很多方法可以在matplotlib
中注释图表(我将假定您正在使用),如下所示
其中的一个基本示例是:
ax.annotate('straight',
xy=(0, 1), xycoords='data',
xytext=(-50, 30), textcoords='offset points',
arrowprops=dict(arrowstyle="->"))
您只需要使用标准count or what you want
/ total count of possibilities
公式计算百分比,然后就可以使用与创建条形图相同的x,y绘制结果并包括一个包含您刚刚计算的百分比的字符串(在上面的示例中替换为“直线”)。这个问题也没有直接的答案,因为您可能想在条形图上稍加注释,这与在条形图上精确绘制有所不同...