python - 如何将计数器列表中的数据显示为图表?
问题描述
我有一个程序可以计算每个数字的出现并将其添加到我的计数器中。我用过收款柜台。打印我的计数器时,我收到存储的数据。
Counter({1856: 109, 1331: 4, 1351: 3, 1341: 2, 1376: 2, 1371: 2, 1356: 1, 1361: 1, 1396: 1})
我的程序以显示此数据结束,但我也想将其显示为图表。有任何想法吗?
此有效载荷是在以下起始偏移处发现的:
The Start Offset: 1856 was Discovered a Total of 109 Times!
The Start Offset: 1331 was Discovered a Total of 4 Times!
The Start Offset: 1351 was Discovered a Total of 3 Times!
The Start Offset: 1341 was Discovered a Total of 2 Times!
The Start Offset: 1376 was Discovered a Total of 2 Times!
The Start Offset: 1371 was Discovered a Total of 2 Times!
The Start Offset: 1356 was Discovered a Total of 1 Times!
The Start Offset: 1361 was Discovered a Total of 1 Times!
The Start Offset: 1396 was Discovered a Total of 1 Times!
解决方案
您有多种选择,但一种流行的选择是matplotlib
.
这是一个简单的条形图,使用matplotlib.pyplot
from collections import Counter
import matplotlib.pyplot as plt
c = Counter({1856: 109, 1331: 4, 1351: 3, 1341: 2, 1376: 2, 1371: 2, 1356: 1, 1361: 1, 1396: 1})
plt.bar([str(key) for key in c], c.values())
plt.show()
推荐阅读
- r - 日期框架未正确解析 H:M:S
- ios - 如何在移动模拟器中测试地图航向功能?
- r - 如何通过posixct将09-Oct-2017这样的日期转换为09-11-2017?
- django - Django 更改模型选择的查询集
- azure-logic-apps - (Azure 逻辑应用):如何从授权应用获取访问令牌
- javascript - bug:ReferenceError: self 未定义 exif-js
- oracle - 数字中尾随零的数量
- git - 在 Gitlab 中使用 SVN 自动同步 Git 存储库
- wso2 - 如何将用户存储和 Oauth 从 4.5.0 迁移到 5.5.0 WSO2 IS
- android - Android Geofencing API 在后台可以正常工作,但不能用于 GPS