如何在Seaborn中用值注释堆积的条形图?

时间:2019-08-21 11:10:01

标签: python-3.x pandas matplotlib plot seaborn

我希望将每个条形图(在y轴上)的值放在文本中。我只在网上找到了针对Matlab绘图/热图的解决方案,但找不到针对堆积条形图的解决方案。任何帮助将不胜感激。

enter image description here

这是我的数据框的样子: dataframe

这就是我想要的情节:

ideal plot

1 个答案:

答案 0 :(得分:0)

如果要将值放在小节的顶部,则应使用此方法。(示例)

       fig, ax = plt.subplots()
       rects1 = ax.bar(ind, men_means, width, color='r', yerr=men_std)
       for rect in rects:
          height = rect.get_height()
          ax.text(rect.get_x() + rect.get_width()/2., 1.05*height,'%d' % int(height),
          ha='center', va='bottom')