# -*- coding: utf-8 -*- """ Created on Thu Feb 3 18:47:48 2022 @author: Rene """ import pandas as pd import numpy as np import matplotlib.pyplot as plt from scipy.stats import norm x = np.arange(0,1001)/1000 LB_x = -30 UB_x = 300 x = (UB_x-LB_x)*x+LB_x pdf_normal_3 = norm.pdf(x,loc=3,scale = 4) cdf_normal_3 = norm.cdf(x,loc=3,scale = 4) pdf_normal_5 = norm.pdf(x,loc=5,scale = 3) cdf_normal_5 = norm.cdf(x,loc=5,scale = 3) pdf_normal_8 = norm.pdf(x,loc=8,scale = 5) cdf_normal_8 = norm.cdf(x,loc=8,scale = 5) # Plotting a four panel figure plt.rc('font', family='serif', size='10') plt.figure(figsize=(10, 5)) Figure = plt.figure(0) Figure.set_figwidth(9) Figure.set_figheight(4.75) Figure.subplots_adjust(hspace=0.5, wspace=0.25) # Adding a panel to the figure Panel = Figure.add_subplot(1,2,1) LB_x = -15 UB_x = 30 off_set_x = 0.025*(UB_x-LB_x) x_lims = (LB_x-off_set_x,UB_x+off_set_x) LB_y = 0 UB_y = max(pdf_normal_5) off_set_y = 0.05*(UB_y-LB_y) y_lims = (LB_y-off_set_y,UB_y+off_set_y) the_x = x the_y = pdf_normal_3 plt.xlim(x_lims) plt.ylim(y_lims) plt.xlabel('x ') plt.ylabel('PDF $f(x)$') title_str = r'PDF : Normal Distributions' plt.title(title_str) plt.axvline(0, lw=2, ls = '-',color = 'lightgray',alpha=0.5) plt.axhline(0, lw=2, ls = '-',color = 'lightgray',alpha=0.5) plt.plot(the_x,the_y, color='red', lw=1) plt.plot(the_x,pdf_normal_5, color='green', lw=1) plt.plot(the_x,pdf_normal_8, color='blue', lw=1) x_values = [3,3] y_values = [0,norm.pdf(3,loc=3,scale = 4)] plt.plot(x_values,y_values, color='black', lw=1, ls=':') x_values = [5,5] y_values = [0,norm.pdf(5,loc=5,scale = 3)] plt.plot(x_values,y_values, color='black', lw=1, ls=':') x_values = [8,8] y_values = [0,norm.pdf(8,loc=8,scale = 5)] plt.plot(x_values,y_values, color='black', lw=1, ls=':') # Adding a panel to the figure Panel = Figure.add_subplot(1,2,2) LB_x = -15 UB_x = 30 off_set_x = 0.025*(UB_x-LB_x) x_lims = (LB_x-off_set_x,UB_x+off_set_x) LB_y = 0 UB_y = 1 off_set_y = 0.05*(UB_y-LB_y) y_lims = (LB_y-off_set_y,UB_y+off_set_y) the_x = x the_y = cdf_normal_3 plt.xlim(x_lims) plt.ylim(y_lims) plt.xlabel('x') plt.ylabel('CDF $F(x) = Pr(X\leq x)$') title_str = r'CDF : Normal Distributions' plt.title(title_str) plt.axvline(0, lw=2, ls = '-',color = 'lightgray',alpha=0.5) plt.axhline(0, lw=2, ls = '-',color = 'lightgray',alpha=0.5) plt.plot(the_x,the_y, color='red', lw=1) plt.plot(the_x,cdf_normal_5, color='green', lw=1) plt.plot(the_x,cdf_normal_8, color='blue', lw=1) x_values = [3,3] y_values = [0,norm.cdf(3,loc=3,scale = 4)] plt.plot(x_values,y_values, color='black', lw=1, ls=':') x_values = [0,3] y_values = [norm.cdf(3,loc=3,scale = 4),norm.cdf(3,loc=3,scale = 4)] plt.plot(x_values,y_values, color='black', lw=1, ls=':') x_values = [5,5] y_values = [0,norm.cdf(5,loc=5,scale = 3)] plt.plot(x_values,y_values, color='black', lw=1, ls=':') x_values = [0,5] y_values = [norm.cdf(5,loc=5,scale = 3),norm.cdf(5,loc=5,scale = 3)] plt.plot(x_values,y_values, color='black', lw=1, ls=':') x_values = [8,8] y_values = [0,norm.cdf(8,loc=8,scale = 5)] plt.plot(x_values,y_values, color='black', lw=1, ls=':') x_values = [0,8] y_values = [norm.cdf(8,loc=8,scale = 5),norm.cdf(8,loc=8,scale = 5)] plt.plot(x_values,y_values, color='black', lw=1, ls=':') plt.savefig('SUM_OF_NORMALS.png', dpi=300)