# -*- 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 expon from scipy.stats import gamma the_lambda = 0.5 x = np.arange(0,101)/100 LB_x = 0 UB_x = 120 x = (UB_x-LB_x)*x+LB_x pdf_exp = expon.pdf(x,scale = 1/the_lambda) cdf_exp = expon.cdf(x,scale = 1/the_lambda) pdf_gamma_30 = gamma.pdf(x,a = 30,scale = 1/the_lambda) cdf_gamma_30 = gamma.cdf(x,a = 30,scale = 1/the_lambda) # 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 = 0 UB_x = 120 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_gamma_30) 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_gamma_30 plt.xlim(x_lims) plt.ylim(y_lims) plt.xlabel('t (in Min)') plt.ylabel('PDF $f(t)$') title_str = r'PDF : $T \sim Gamma(30,0.5)$' 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 = [60,60] y_values = [0,gamma.pdf(60,a = 30,scale = 1/the_lambda)] 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 = 0 UB_x = 120 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_gamma_30 plt.xlim(x_lims) plt.ylim(y_lims) plt.xlabel('t (in Min)') plt.ylabel('CDF $F(t) = Pr(T \leq x)$') title_str = r'CDF : $T \sim Gamma(30,0.5)$' 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 = [60,60] y_values = [0,gamma.cdf(60,a = 30,scale = 1/the_lambda)] plt.plot(x_values,y_values, color='black', lw=1, ls=':') x_values = [0,60] y_values = [gamma.cdf(60,a = 30,scale = 1/the_lambda),gamma.cdf(60,a = 30,scale = 1/the_lambda)] plt.plot(x_values,y_values, color='black', lw=1, ls=':') text_str = f'{gamma.cdf(60,a = 30,scale = 1/the_lambda):4.3f}' plt.text(5,gamma.cdf(60,a = 30,scale = 1/the_lambda),text_str,color = 'black', size = 8,horizontalalignment = 'left', verticalalignment = 'bottom') plt.savefig('GAMMA_PDF.png', dpi=300)