In [ ]:
from scipy.stats import norm
import ipywidgets as widgets
import matplotlib.pyplot as plt
import numpy as np
def simulation_Uniform_histogram(sample_size = 100):
plt.figure(figsize=(5,5))
x = np.random.rand(sample_size)
plt.hist(x, edgecolor='#60605030', linewidth=1.2, facecolor='lightblue',density=True)
plt.ylim(0,2)
plt.ylabel('Frequency')
plt.xlim(-1,2)
plt.xlabel('x')
plt.axhline(y=1, color='r', linestyle='-')
plt.grid()
plt.show()
In [ ]:
widgets.interact(simulation_Uniform_histogram, sample_size = (0,1000,100))
In [ ]:
def simulation_Normal_histogram(sample_size = 100):
plt.figure(figsize=(5,5))
x = np.random.normal(loc=0.0, scale=1.0, size=sample_size)
mu = np.mean(x)
sigma = np.std(x)
x1 = np.linspace(mu - 3*sigma, mu + 3*sigma, 1000) # Generate 1000 points within 3 standard deviations from the mean
y = norm.pdf(x1, mu, sigma)
plt.hist(x, edgecolor='#60605030', linewidth=1.2, facecolor='lightblue',density=True)
plt.plot(x1,y,'k--')
plt.ylim(0,0.6)
plt.ylabel('Frequency')
plt.xlim(-4,4)
plt.xlabel('x')
plt.axvline(x=mu, color='r', linestyle='--')
plt.grid()
plt.show()
In [ ]:
widgets.interact(simulation_Normal_histogram, sample_size = (0,10000,100))
In [ ]: