# -*- coding: utf-8 -*- """ Created on Sat Mar 7 10:41:51 2020 @author: Johan Rene van Dorp """ import pandas as pd import numpy as np import matplotlib.pyplot as plt import Dist_Library as dl df = pd.read_csv('OldFaithFul.csv') Durations = df["Duration (s)"] WaitingTimes = df["Waiting Time (Min)"] #Plotting a four panel histogram plot of the durations with different # number of bins plt.rc('font', family='serif', size='10') plt.figure(figsize=(10, 10)) Hist_Figure = plt.figure() Hist_Figure.subplots_adjust(hspace=0.4, wspace=0.4) off_set_x = 10 # Calculating the histogram data for the left top panel Number_of_bins = 8 LB = 90 UB = 330 bins = np.linspace(LB, UB, Number_of_bins+1) Duration_hist_data = dl.Estimate_empirical_histogram_table(bins,Durations) # Adding the left top panel with the theoretical pmf the_bounds = np.append(Duration_hist_data["LB"][0],Duration_hist_data["UB"]) the_density = np.append(0,Duration_hist_data["Bin PDF"]) x_lims = (LB-off_set_x,UB+off_set_x) y_lims = (0,0.02) Panel = Hist_Figure.add_subplot(2,2,1) dl.add_pmf_density_hist_to_figure_panel(Panel,the_bounds,the_density,'indianred') plt.xlim(x_lims) plt.ylim(y_lims) plt.xlabel('Duration (in Sec)') plt.ylabel('Density') text_str = '# Bins '+str(Number_of_bins) plt.text(160,0.0175,text_str,color = 'red',size = 10) # Calculating the histogram data for the left top panel Number_of_bins = 100 LB = 90 UB = 330 bins = np.linspace(LB, UB, Number_of_bins+1) Duration_hist_data = dl.Estimate_empirical_histogram_table(bins,Durations) # Adding the left top panel with the theoretical pmf the_bounds = np.append(Duration_hist_data["LB"][0],Duration_hist_data["UB"]) the_density = np.append(0,Duration_hist_data["Bin PDF"]) x_lims = (LB-off_set_x,UB+off_set_x) y_lims = (0,0.02) Panel = Hist_Figure.add_subplot(2,2,2) dl.add_pmf_density_hist_to_figure_panel(Panel,the_bounds,the_density,'indianred') plt.xlim(x_lims) plt.ylim(y_lims) plt.xlabel('Duration (in Sec)') plt.ylabel('Density') text_str = '# Bins '+str(Number_of_bins) plt.text(160,0.0175,text_str,color = 'red',size = 10) # Calculating the histogram data for the bottom left panel Number_of_bins = 3 LB = 90 UB = 330 bins = np.linspace(LB, UB, Number_of_bins+1) Duration_hist_data = dl.Estimate_empirical_histogram_table(bins,Durations) # Adding the left top panel with the theoretical pmf the_bounds = np.append(Duration_hist_data["LB"][0],Duration_hist_data["UB"]) the_density = np.append(0,Duration_hist_data["Bin PDF"]) x_lims = (LB-off_set_x,UB+off_set_x) y_lims = (0,0.02) Panel = Hist_Figure.add_subplot(2,2,3) dl.add_pmf_density_hist_to_figure_panel(Panel,the_bounds,the_density,'indianred') plt.xlim(x_lims) plt.ylim(y_lims) plt.xlabel('Duration (in Sec)') plt.ylabel('Density') text_str = '# Bins '+str(Number_of_bins) plt.text(160,0.0175,text_str,color = 'red',size = 10) # Calculating the histogram data for the bottom right panel Number_of_bins = 22 LB = 90 UB = 330 bins = np.linspace(LB, UB, Number_of_bins+1) Duration_hist_data = dl.Estimate_empirical_histogram_table(bins,Durations) # Adding the left top panel with the theoretical pmf the_bounds = np.append(Duration_hist_data["LB"][0],Duration_hist_data["UB"]) the_density = np.append(0,Duration_hist_data["Bin PDF"]) x_lims = (LB-off_set_x,UB+off_set_x) y_lims = (0,0.02) Panel = Hist_Figure.add_subplot(2,2,4) dl.add_pmf_density_hist_to_figure_panel(Panel,the_bounds,the_density,'indianred') plt.xlim(x_lims) plt.ylim(y_lims) plt.xlabel('Duration (in Sec)') plt.ylabel('Density') text_str = '# Bins '+str(Number_of_bins) plt.text(160,0.0175,text_str,color = 'red',size = 10) plt.suptitle('Old Faithful Duration Data') plt.savefig('Old_Faithful_Duration.png', dpi=1200)