【发布时间】:2021-10-07 08:44:32
【问题描述】:
对于六面骰子的滚动,我需要随机模拟该事件 50 次,并在使用箱数 = 6 时绘制骰子上每个数字的结果直方图
我尝试了以下方法:
import random
test_data = [0, 0, 0, 0, 0, 0]
n = 50
for i in range(n):
result = random.randint(1, 6)
test_data[result - 1] = test_data[result - 1] + 1
plt.hist(test_data,bins=6)
有没有办法在 x 轴上绘制骰子的数字并在 y 轴上绘制骰子上每个数字的结果?
【问题讨论】:
-
使用
seaborn.countplot或barplot
标签: python pandas matplotlib histogram probability