Matplotlib – 使用 Python 中的元组元素列表制作频率直方图
matplotlibpythondata visualization更新于 2025/11/5 22:04:17
要使用 Python 中的元组元素列表制作频率直方图,我们可以采取以下步骤 −
- 设置图形大小并调整子图之间和周围的填充。
- 制作元组、数据列表。
- 迭代数据后,制作频率和索引列表。
- 使用 bar() 方法制作条形图。
- 要显示图形,请使用 show() 方法。
示例
import matplotlib.pyplot as plt
plt.rcParams["figure.figsize"] = [7.00, 3.50]
plt.rcParams["figure.autolayout"] = True
data = [("a", 1), ("c", 3), ("d", 4), ("b", 2),
("e", 7), ("f", 3), ('g', 2)]
ind = []
fre = []
for item in data:
ind.append(item[0])
fre.append(item[1])
plt.bar(ind, fre)
plt.show()
输出
它将产生以下输出 −


相关文章
有用资源
python 参考教程 - 该教程包含有关 python 的更多信息:https://www.cainiaomax.com/python/

