python-3.x - 如何在条形图中启用条形图上的数字
问题描述
如何在条形图中的每个条形上启用数字。
我无法找到我做错的地方。
注意:使用的 sample-superstore 数据集。
我尝试使用以下代码出现错误,例如“TypeError: unsupported operand type(s) for -: 'str' and 'float'”
` Grouped_data= df.groupby(['Region'],as_index=False).count()
import matplotlib.pyplot as plt
import numpy as np
barWidth = 0.9
x=np.arange(len(Grouped_data))
y=list(Grouped_data['Row ID'])
xx=list(Grouped_data['Region'])
plt.legend()
plt.bar(x,y,width = barWidth,color=['lime','r','k','tan'])
plt.xticks(x,xx,rotation=90)
label=y
for i in range(len(xx)):
plt.text(x = xx[i]-0.5 , y = y[i]+0.1, s = label[i],size = 6)
plt.subplots_adjust(bottom= 0.2, top = 0.98)
plt.show()
我想查看图表中每个条形的值。
解决方案
我改变了我的状况,然后我得到了想要的结果。
for i in range(len(x)):
plt.text(x = x[i]-0.2 , y = y[i]+0.1, s = label[i],size = 10)
推荐阅读
- jmeter - 我们可以将 HTTP 缓存管理器用于 REST API 负载运行吗
- php - 如何让 Laravel 8 会话在 Heroku 上运行?由于它们没有正确保存
- java - 如何将我的 Docker 应用程序连接到远程数据库?
- python - 在 mac 上不起作用 python curses 的 getstr()
- javascript - webdriverio中单个断言中的多个值
- javascript - 使用 JavaScript 检查瑞士电话号码
- json - 从 json 中获取具有值的列
- python - 如何使用 Threading.Timer 每 0.05 秒精确地从 Modbus 服务器读取数据?
- php - 从原点计算坐标
- geocoding - 有没有办法在 HERE 地图地理编码器自动完成 API 中提供政治观点?