# -*- 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 df = pd.read_csv('OldFaithFul.csv') Durations = df["Duration (s)"] WaitingTimes = df["Waiting Time (Min)"] # Plotting Empirical Cumulative Distribution Functions plt.rc('font', family='serif', size='10') plt.figure(figsize=(10, 5)) ECDF_Figure = plt.figure() ECDF_Figure.subplots_adjust(hspace=0.4, wspace=0.4) off_set_x = 10 # Plotting the Empirical CDF of the Durations n_d = len(Durations) LB = 90 UB = 330 Durations.ordered = np.sort(Durations) Durations.ordered = np.append(LB-off_set_x,Durations.ordered) Durations.ordered = np.append(Durations.ordered,UB+off_set_x) F = np.linspace(0,1,n_d) F = np.append(0,F) F = np.append(F,1) x_lims = (LB-off_set_x,UB+off_set_x) y_lims = (-0.05,1.1) Panel = ECDF_Figure.add_subplot(1,2,1) plt.step(Durations.ordered,F,lw = 1,color ='indianred') plt.xlim(x_lims) plt.ylim(y_lims) plt.xlabel('Duration (in Sec)') plt.ylabel('Empirical CDF $\hat{F}(d) = Pr(D \leq d)$') plt.axvline(0, lw=2, ls = '-',color = 'lightgray',alpha=0.5) plt.axhline(0, lw=2, ls = '-',color = 'lightgray',alpha=0.5) plt.axhline(1, lw=2, ls = ':',color = 'lightgray',alpha=0.5) text_str = 'n = '+str(n_d) plt.text(160,0.9,text_str,color = 'red',size = 10) # Plotting the Empirical CDF of the Waiting Times LB = 40 UB = 100 n_w = len(WaitingTimes) WaitingTimes.ordered = np.sort(WaitingTimes) WaitingTimes.ordered = np.append(LB-off_set_x,WaitingTimes.ordered) WaitingTimes.ordered = np.append(WaitingTimes.ordered,UB+off_set_x) F = np.linspace(0,1,n_d) F = np.append(0,F) F = np.append(F,1) x_lims = (LB-off_set_x,UB+off_set_x) y_lims = (-0.05,1.1) Panel = ECDF_Figure.add_subplot(1,2,2) plt.step(WaitingTimes.ordered,F,lw = 1,color ='skyblue') plt.xlim(x_lims) plt.ylim(y_lims) plt.xlabel('Waiting Times (in Min)') plt.ylabel('Empirical CDF $\hat{F}(w) = Pr(W \leq w)$') plt.axvline(0, lw=2, ls = '-',color = 'lightgray',alpha=0.5) plt.axhline(0, lw=2, ls = '-',color = 'lightgray',alpha=0.5) plt.axhline(1, lw=2, ls = ':',color = 'lightgray',alpha=0.5) text_str = 'n = '+str(n_w) plt.text(55,0.9,text_str,color = 'red',size = 10) ECDF_Figure.suptitle('Empirical CDFs Old Faithful Data',size='14') plt.savefig('Old_Faithful_ECDF.png', dpi=1200)