In [1]:
from random import randint
from collections import Counter
lances = 10000
ct = Counter()
for _ in range(lances):
ct[randint(1, 6)] += 1
ct
Out[1]:
In [2]:
categorias, contagens = zip(*sorted(ct.items()))
categorias, contagens
Out[2]:
In [3]:
porcentagens = [c/lances * 100 for c in contagens]
In [4]:
%matplotlib inline
import matplotlib.pyplot as plt
plt.figure()
plt.bar(categorias, porcentagens)
plt.axhline(1/6 * 100, color='r')
plt.ylabel('%')
plt.xlabel('resultados d6')
Out[4]:
In [5]:
lances = 10000
ct = Counter()
for _ in range(lances):
ct[randint(1, 6) + randint(1, 6)] += 1
In [6]:
import numpy as np
categorias, contagens = zip(*sorted(ct.items()))
porcentagens = [c/lances * 100 for c in contagens]
categorias = np.asarray(categorias)
In [7]:
plt.figure()
plt.bar(categorias, porcentagens)
plt.xticks(categorias + 0.5, categorias)
plt.xlim(min(categorias), max(categorias)+1)
plt.ylabel('%')
plt.xlabel('resultados d6+d6')
Out[7]: