# -*- coding: utf-8 -*- """ Created on Mon Feb 28 08:46:50 2022 @author: Rene """ import GeneralizedTrapezoidal as GT import numpy as np from scipy.stats import uniform import matplotlib.pyplot as plt LB_x = -0.5 UB_x = 2.5 x = np.linspace(LB_x,UB_x,1000) a = 0 b = 1 pdf_1 = uniform.pdf(x,loc = a,scale = b) cdf_1 = uniform.cdf(x,loc = a,scale = b) pdf_1 a = 0 b = 1 c = 1 d = 2 m = 2 n = 2 alpha = 1 pdf_2 = GT.GT_pdf(x,a,b,c,d,m,n,alpha) cdf_2 = GT.GT_cdf(x,a,b,c,d,m,n,alpha) # 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(2,2,1) LB_x = -0.25 UB_x = 2.25 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_1) off_set_y = 0.1*(UB_y-LB_y) y_lims = (LB_y-off_set_y,UB_y+off_set_y) the_x = x the_y = pdf_1 plt.xlim(x_lims) plt.ylim(y_lims) plt.xlabel('x') plt.ylabel('PDF $f(x)$') title_str = r'PDF : $X \sim Unif(0,1)$' 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='blue', lw=1) # Adding a panel to the figure Panel = Figure.add_subplot(2,2,2) LB_x = -0.25 UB_x = 2.25 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_2) off_set_y = 0.1*(UB_y-LB_y) y_lims = (LB_y-off_set_y,UB_y+off_set_y) the_x = x the_y = pdf_2 plt.xlim(x_lims) plt.ylim(y_lims) plt.xlabel('x') plt.ylabel('PDF $f(x)$') title_str = r'PDF : $X \sim$ Sum of two $Unif(0,1)$' 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) x_values = [1,1] y_values = [0,GT.GT_pdf(1,a,b,c,d,m,n,alpha)[0]] plt.plot(x_values,y_values, color='black', lw=1, ls=':') # Adding a panel to the figure Panel = Figure.add_subplot(2,2,3) LB_x = -0.25 UB_x = 2.25 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(cdf_1) off_set_y = 0.1*(UB_y-LB_y) y_lims = (LB_y-off_set_y,UB_y+off_set_y) the_x = x the_y = cdf_1 plt.xlim(x_lims) plt.ylim(y_lims) plt.xlabel('x') plt.ylabel('CDF $F(x) = Pr(X \leq x)$') title_str = r'CDF : $X \sim Unif(0,1)$' 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='blue', lw=1) x_values = [1,1] y_values = [0,uniform.pdf(1,loc = a,scale = b)] plt.plot(x_values,y_values, color='black', lw=1, ls=':') # Adding a panel to the figure Panel = Figure.add_subplot(2,2,4) LB_x = -0.25 UB_x = 2.25 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(cdf_2) off_set_y = 0.1*(UB_y-LB_y) y_lims = (LB_y-off_set_y,UB_y+off_set_y) the_x = x the_y = cdf_2 plt.xlim(x_lims) plt.ylim(y_lims) plt.xlabel('x') plt.ylabel('CDF $F(x) = Pr(X \leq x)$') title_str = r'PDF : $X \sim$ Sum of two $Unif(0,1)$' 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) x_values = [1,1] y_values = [0,GT.GT_cdf(1,a,b,c,d,m,n,alpha)[0]] plt.plot(x_values,y_values, color='black', lw=1, ls=':') x_values = [0,1] y_values = [GT.GT_cdf(1,a,b,c,d,m,n,alpha)[0],GT.GT_cdf(1,a,b,c,d,m,n,alpha)[0]] plt.plot(x_values,y_values, color='black', lw=1, ls=':') plt.savefig('SUM_OF_UNFORMS.png', dpi=300)