将百分比标签添加到石斑制条形图
我一直在整天成功工作时遇到困难。任何人都能提供的任何帮助将受到极大的赞赏。
本质上,我只需要在每个条形图中的每个条形图中上方的百分比列表中添加每个项目的值,这些列表由附件代码产生。我已经尝试了AX.ANG.ANDATATE和其他多个代码选项,但似乎没有任何作用。当然,这是用户错误,但是我不确定如何自己拍摄麻烦。
非常感谢您提供的任何帮助。
这是我正在使用的代码:
import pandas as pd
import numpy as np
import os
import matplotlib.pyplot as plt
import sys
Paid = [5858, 6351, 5111]
Unpaid = [6917, 5738, 4006]
Percentages = [45.9, 54.1, 52.5, 47.5, 56.1, 43.9]
n=3
r = np.arange(n)
width = 0.25
plt.bar(r, Paid, color = 'b',
width = width, edgecolor = 'black',
label='Paid')
plt.bar(r + width, Unpaid, color = 'g',
width = width, edgecolor = 'black',
label='Unpaid')
plt.xlabel("Year")
plt.ylabel("Count")
plt.title("YOY Paid v. Unpaid WBL Opportunities")
plt.xticks(r + width/2,['2019-2020','2020-2021','2021-2022'])
plt.legend()
plt.show()
I've been having trouble getting this to work successfully all day. Any help that anyone could offer would be immensely appreciated.
Essentially, I just need to add the value of each item in the Percentages list above each bar in the grouped bar chart that is produced with the attached code. I've tried ax.annotate and multiple other code options, but nothing seems to be working. Of course this is user error, but I'm unsure how to trouble shoot on my own.
Thanks so much for any help you can offer.
Here is the code I'm working with:
import pandas as pd
import numpy as np
import os
import matplotlib.pyplot as plt
import sys
Paid = [5858, 6351, 5111]
Unpaid = [6917, 5738, 4006]
Percentages = [45.9, 54.1, 52.5, 47.5, 56.1, 43.9]
n=3
r = np.arange(n)
width = 0.25
plt.bar(r, Paid, color = 'b',
width = width, edgecolor = 'black',
label='Paid')
plt.bar(r + width, Unpaid, color = 'g',
width = width, edgecolor = 'black',
label='Unpaid')
plt.xlabel("Year")
plt.ylabel("Count")
plt.title("YOY Paid v. Unpaid WBL Opportunities")
plt.xticks(r + width/2,['2019-2020','2020-2021','2021-2022'])
plt.legend()
plt.show()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要消除条形标签的歧义,应单独编写它们:
To remove the ambiguity about the bar labels, they should be written separately: