#! /usr/bin/env python3 # def faithful_both ( ): #*****************************************************************************80 # ## faithful_both() analyzes, displays, and normalizes the data # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 27 September 2023 # # Author: # # John Burkardt # import numpy as np print ( '' ) print ( 'faithful_both():' ) print ( ' Initial analysis and display of Old Faithful data.' ) # # Read the data. # data = np.loadtxt ( 'faithful_data.txt' ) print ( '' ) print ( ' Statistics for Old Faithful eruption and wait times' ) print ( ' data.shape = ', data.shape ) print ( ' data min = ', np.min ( data, axis = 0 ) ) print ( ' data mean = ', np.mean ( data, axis = 0 ) ) print ( ' data max = ', np.max ( data, axis = 0 ) ) print ( ' data var = ', np.var ( data, axis = 0 ) ) print ( ' data std = ', np.std ( data, axis = 0 ) ) # # Create x and y. # print ( '' ) print ( ' Display raw data' ) x = data[:,0] y = data[:,1] faithful_display ( x, y, 'faithful_raw.png' ) print ( '' ) print ( ' Display normalized data' ) xn = ( x - np.min ( x ) ) / ( np.max ( x ) - np.min ( x ) ) yn = ( y - np.min ( y ) ) / ( np.max ( y ) - np.min ( y ) ) faithful_display ( xn, yn, 'faithful_normalized.png' ) datan = np.column_stack ( [ xn, yn ] ) np.savetxt ( 'faithful_normalized.txt', datan ) print ( '' ) print ( ' Display standardized data' ) xs = ( x - np.mean ( x ) ) / np.std ( x ) ys = ( y - np.mean ( y ) ) / np.std ( y ) faithful_display ( xs, ys, 'faithful_standardized.png' ) datas = np.column_stack ( [ xs, ys ] ) np.savetxt ( 'faithful_standardized.txt', datas ) # # Terminate. # print ( '' ) print ( 'faithful_both():' ) print ( ' Normal end of execution.' ) return def faithful_display ( x, y, filename ): #*****************************************************************************80 # ## faithful_display() displays the Old Faithful data. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 21 January 2022 # # Author: # # John Burkardt # import matplotlib.pyplot as plt import numpy as np import platform plt.plot ( x, y, 'k.', markersize = 10 ) plt.xlabel ( '<-- Erupt -->', fontsize = 16 ) plt.ylabel ( '<-- Wait -->', fontsize = 16 ) plt.title ( filename ) plt.grid ( True ) plt.axis ( 'equal' ) plt.savefig ( filename ) print ( ' Graphics saved as "%s"' % ( filename ) ) plt.show ( ) plt.clf ( ) return if ( __name__ == "__main__" ): faithful_both ( )