#! /usr/bin/env python3 # def faithful_wait ( ): #*****************************************************************************80 # ## faithful_wait() computes and displays wait statistics. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 27 September 2023 # # Author: # # John Burkardt # import matplotlib.pyplot as plt import numpy as np import platform print ( '' ) print ( 'faithful_wait():' ) print ( ' Python version: %s' % ( platform.python_version ( ) ) ) print ( ' Compute and display Old Faithful wait-time statistics.' ) # # Read the data. # data = np.loadtxt ( 'faithful_data.txt' ) x = data[:,0] y = data[:,1] # # Report statistics. # print ( '' ) print ( ' Statistics for Old Faithful wait times y' ) print ( ' y.shape = ', y.shape ) print ( ' y min = ', np.min ( y ) ) print ( ' y mean = ', np.mean ( y ) ) print ( ' y max = ', np.max ( y ) ) print ( ' y var = ', np.var ( y ) ) print ( ' y std = ', np.std ( y ) ) # # Histogram of wait times (y) # y_mean = np.mean ( y ) y_std = np.std ( y ) plt.clf ( ) plt.hist ( y, bins = 20 ) bot, top = plt.ylim ( ) plt.plot ( [y_mean-y_std,y_mean-y_std], [0.0,top], 'r-', linewidth = 3 ) plt.plot ( [y_mean+y_std,y_mean+y_std], [0.0,top], 'r-', linewidth = 3 ) plt.xlabel ( '<-- Wait -->', fontsize = 16 ) plt.ylabel ( '<-- Frequency -->', fontsize = 16 ) plt.title ( 'Old Faithful waiting times', fontsize = 16 ) plt.grid ( True ) plt.axis ( 'equal' ) filename = 'faithful_wait.png' plt.savefig ( filename ) print ( ' Graphics saved as "%s"' % ( filename ) ) plt.show ( ) return if ( __name__ == "__main__" ): faithful_wait ( )