import numpy as np import matplotlib.pyplot as plt # %% Number of events (experiments; draws; trials): n = 10 # %% Params of choice(): sample_space = np.array([1, 2, 3, 4, 5, 6]) sample_size = 1 replace = True prob = [1/6, 1/6, 1/6, 1/6, 1/6, 1/6] # %% Initialization: population = np.zeros(n) # %% For loop realizing the n trials: for k in range(0, n): # Sample number k (event number k): sample_k = np.random.choice( sample_space, sample_size, replace, prob) population[k] = sample_k # %% Generating histogram data: num_bins = len(sample_space) histogram_data = np.histogram(population, num_bins) histogram_data_norm = histogram_data[0]/n # %% Plotting: plt.close('all') # Closes all figures before plotting fig1 = plt.figure(num=1, figsize=(30/2.54, 24/2.54))#Inch plt.bar(sample_space, histogram_data_norm, width=0.95) plt.plot(sample_space, prob, 'ro') plt.xlabel('Samples (pips)') plt.ylabel('Frequency') # plt.savefig('plot_distr_dice_10.pdf') # plt.savefig('plot_distr_dice_1000000.pdf') plt.show()