python - 如何命名堆叠条形图中的每个条形标签?
问题描述
我这里有一个简单的 DataFrame。我无法理解或找到标记每个条的简单方法。
import pandas as pd
import matplotlib.pyplot as plt
India = pd.DataFrame({'Year' : [1980 , 1984, 1988 , 1992, 1996 , 2000 , 2004, 2008 , 2012,
2016 , 2020] ,
'Gold' : [1, 0,0,0,0,0,0,1,0,0,1],
'Silver': [0,0,0,0,0,0,1,0,2,1,2],
'Bronze' : [0,0,0,0,1,1,0,2,4,1,4] })
India = India.set_index('Year')
India.plot(kind='bar' , stacked = 'true' , figsize = (8,5))
plt.xticks(rotation = 0)
plt.legend(['Gold Medal','Silver Medal','Bronze Medal'] , title = "Medal Category" )
plt.title("Olympic Medal Trend - India (1980 - 2020)")
plt.xlabel("Summer Olympics held(years)")
plt.ylabel("Number of Medals won")
totals = India.sum(axis=1)
print(totals)
y_offset = 4
我不知道如何进一步进行。我只想要“y”的总数或高度作为条形标签。
我尝试了此处提供的解决方案,但总是为每个条而不是整个条获得标签。
解决方案
推荐阅读
- css - 带有 :not 的 CSS 类通配符
- microsoft-graph-api - 无法通过图表判断租户是否启用了 Teams
- constraint-programming - MiniZinc:获取一组超集数组
- javascript - 无法弄清楚“未定义”错误谷歌地图距离服务背后的逻辑
- python - 手动生成的 JSON 有效,但通过 json.dumps 创建的 JSON 不起作用,即使输出看起来完全相同
- reactjs - 当我的映射输入组件已经具有唯一键时,为什么我会收到“唯一键道具”警告?
- java - BasicDataSource 的转换异常
- javascript - JavaScript ES6 (<<) 中的按位左移是否在 63 移位以上循环?
- ajax - 通过 ajax 从 html 表单发送单选选项
- angular - Angular Material 表单字段行为不正确