# -*- coding: utf-8 -*- """ Created on Tue Mar 10 11:05:47 2020 @author: Rene """ import pandas as pd import numpy as np import matplotlib.pyplot as plt import Dist_Library as dl df = pd.read_csv('DrillTime.csv') DryTimes = df["Dry"] WetTimes = df["Wet"] Depth = df["Depth"] mu_dry = np.mean(DryTimes) mu_wet = np.mean(WetTimes) # Calculating the histogram data for the left panel Number_of_bins = 15 LB = min(np.min(DryTimes),np.min(WetTimes)) UB = max(np.max(DryTimes),np.max(WetTimes)) off_set_x = 100 bins = np.linspace(LB, UB, Number_of_bins+1) Dry_hist_data = dl.Estimate_empirical_histogram_table(bins,DryTimes) Dry_bounds = np.append(Dry_hist_data["LB"][0],Dry_hist_data["UB"]) Dry_density = np.append(0,Dry_hist_data["Bin PDF"]) Wet_hist_data = dl.Estimate_empirical_histogram_table(bins,WetTimes) Wet_bounds = np.append(Wet_hist_data["LB"][0],Wet_hist_data["UB"]) Wet_density = np.append(0,Wet_hist_data["Bin PDF"]) DryTimes.ordered = np.sort(DryTimes) DryTimes.ordered = np.append(LB-off_set_x,DryTimes.ordered) DryTimes.ordered = np.append(DryTimes.ordered,UB+off_set_x) WetTimes.ordered = np.sort(WetTimes) WetTimes.ordered = np.append(LB-off_set_x,WetTimes.ordered) WetTimes.ordered = np.append(WetTimes.ordered,UB+off_set_x) n_data = len(DryTimes) F = np.arange(1,(n_data+1))/n_data F = np.append(0,F) F = np.append(F,1) # Plotting a two panel histogram plot of the drill times plt.rc('font', family='serif', size='10') plt.figure(figsize=(10, 10)) Hist_Figure = plt.figure() Hist_Figure.set_figwidth(9) Hist_Figure.set_figheight(4.5) Hist_Figure.subplots_adjust(hspace=0.3, wspace=0.3) plt.rcParams['xtick.labelsize'] = 5 plt.rcParams['ytick.labelsize'] = 5 # Adding the left top panel with the theoretical pmf x_lims = (LB-off_set_x,UB+off_set_x) y_lims = (0,0.005) Panel = Hist_Figure.add_subplot(2,2,1) dl.add_pmf_density_hist_to_figure_panel(Panel,Dry_bounds,Dry_density,'indianred') dl.add_pmf_density_hist_to_figure_panel(Panel,Wet_bounds,Wet_density,'skyblue') plt.xlim(x_lims) plt.ylim(y_lims) plt.xlabel('Drill Time') plt.ylabel('Empirical Density',size = 5) text_str = '# Bins '+str(Number_of_bins) plt.text(500,0.0045,text_str,color = 'red',size = 5) # Adding the Right top panel with the empirical cdfs x_lims = (LB-off_set_x,UB+off_set_x) y_lims = (-0.05,1.05) Panel = Hist_Figure.add_subplot(2,2,2) plt.axvline(0, lw=1, ls = '-',color = 'lightgray',alpha=0.5) plt.axhline(0, lw=1, ls = '-',color = 'lightgray',alpha=0.5) plt.axhline(1, lw=1, ls = ':',color = 'lightgray',alpha=0.5) plt.xlim(x_lims) plt.ylim(y_lims) plt.xlabel('Drill Time') plt.ylabel('Empirical CDF $\hat{F}(t) = Pr(T \leq t)$', size = 5) plt.plot(DryTimes.ordered,F,color = 'IndianRed',label = 'Dry',lw = 1) plt.plot(WetTimes.ordered,F,color = 'skyblue', label = 'Wet', lw = 1) plt.axvline(mu_dry, lw=1, ls = ':',color = 'IndianRed',alpha=0.5) plt.axvline(mu_wet, lw=1, ls = ':',color = 'skyblue',alpha=0.5) text_str = f'{mu_dry:5.1f}' plt.text(mu_dry+10,0.05,text_str,color = 'indianred', size = 5) text_str = f'{mu_wet:5.1f}' plt.text(mu_wet+10,0.1,text_str,color = 'skyblue', size = 5) plt.legend(loc='best',prop={'size': 5}) # Adding the left bottom panel with the scatter plot of the dry drill times LB_depth = np.min(Depth) UB_depth = np.max(Depth) y_lims = (LB-off_set_x,UB+off_set_x) x_lims = (0, 425) Panel = Hist_Figure.add_subplot(2,2,3) plt.scatter(Depth,DryTimes,color ='indianred', s = 1) plt.xlim(x_lims) plt.ylim(y_lims) plt.xlabel('Depth') plt.ylabel('Dry Drill Time', size = 5) plt.axvline(0, lw=2, ls = '-',color = 'lightgray',alpha=0.5) plt.axhline(0, lw=2, ls = '-',color = 'lightgray',alpha=0.5) plt.axhline(mu_dry, lw=1, ls = ':',color = 'IndianRed',alpha=0.5) text_str = f'{mu_dry:5.1f}' plt.text(10,mu_dry+15,text_str,color = 'indianred', size = 5) # Adding the right bottom panel with the scatter plot of the wet drill times LB_depth = np.min(Depth) UB_depth = np.max(Depth) y_lims = (LB-off_set_x,UB+off_set_x) x_lims = (0, 425) Panel = Hist_Figure.add_subplot(2,2,4) plt.scatter(Depth,WetTimes,color ='skyblue', s = 1) plt.xlim(x_lims) plt.ylim(y_lims) plt.xlabel('Depth') plt.ylabel('Wet Drill Time', size = 5) plt.axvline(0, lw=2, ls = '-',color = 'lightgray',alpha=0.5) plt.axhline(0, lw=2, ls = '-',color = 'lightgray',alpha=0.5) plt.axhline(mu_wet, lw=1, ls = ':',color = 'Skyblue',alpha=0.5) text_str = f'{mu_wet:5.1f}' plt.text(10,mu_wet+15,text_str,color = 'SkyBlue', size = 5) Hist_Figure.suptitle('Drill Time Data Example',size='14') plt.savefig('Drill_Time.png', dpi=1200)