import numpy as np import matplotlib.pyplot as plt # %% Generating random samples with normal(): mu = 10 sigma = 5 sample_size = 100 samples = np.random.normal(mu, sigma, sample_size) # %% Normal distribution function: x_low = -10 x_high = 30 dx = 0.01 x_array = np.arange(x_low, x_high+dx, dx) pdf_array = ((1/(sigma*np.sqrt(2*np.pi))) *np.exp(-((x_array-mu)**2/(2*(sigma**2))))) # %% Plotting histogram of samples and normal dist function: plt.close('all') fig1 = plt.figure(num=1, figsize=(30/2.54, 24/2.54))#Inch # %% Plotting normalized histogram: num_bins = sample_size plt.hist(samples, num_bins, density=True) # %% Plotting normal dist function: plt.plot(x_array, pdf_array,'r', linewidth=5) plt.grid() plt.title('Normalized histogram and normal distr fun') plt.xlabel('x') plt.ylabel('Relative occurancies and probabilty density') # plt.savefig('plot_normal_dist.pdf') plt.show()