#! /usr/bin/env python3 # def faithful_data ( ): #*****************************************************************************80 # ## faithful_data() displays the Old Faithful data. # # Licensing: # # This code is distributed under the MIT license. # # Modified: # # 21 January 2022 # # Author: # # John Burkardt # import matplotlib.pyplot as plt import numpy as np import platform print ( '' ) print ( 'faithful_plot:' ) print ( ' Python version: %s' % ( platform.python_version ( ) ) ) print ( ' Display Old Faithful (Erupt,Quiet) observations.' ) # # Read the data. # data = np.loadtxt ( 'faithful_data.txt' ) # # Create x and y. # x = data[:,0] y = data[:,1] plt.plot ( x, y, 'k.', markersize = 10 ) plt.xlabel ( '<-- Erupt -->', fontsize = 16 ) plt.ylabel ( '<-- Quiet -->', fontsize = 16 ) plt.title ( 'Old Faithful eruptions (unscaled)', fontsize = 16 ) plt.grid ( True ) plt.axis ( 'equal' ) filename = 'faithful_data_unscaled.png' plt.savefig ( filename ) print ( ' Graphics saved as "%s"' % ( filename ) ) plt.show ( ) plt.clf ( ) plt.plot ( x, y, 'k.', markersize = 10 ) plt.xlabel ( '<-- Erupt -->', fontsize = 16 ) plt.ylabel ( '<-- Quiet -->', fontsize = 16 ) plt.title ( 'Old Faithful eruptions (scaled)', fontsize = 16 ) plt.grid ( True ) filename = 'faithful_data_scaled.png' plt.savefig ( filename ) print ( ' Graphics saved as "%s"' % ( filename ) ) plt.show ( ) plt.clf ( ) x = ( x - np.min ( x ) ) / ( np.max ( x ) - np.min ( x ) ) y = ( y - np.min ( y ) ) / ( np.max ( y ) - np.min ( y ) ) plt.plot ( x, y, 'k.', markersize = 10 ) plt.xlabel ( '<-- Erupt -->', fontsize = 16 ) plt.ylabel ( '<-- Quiet -->', fontsize = 16 ) plt.title ( 'Old Faithful eruptions (normalized)', fontsize = 16 ) plt.grid ( True ) filename = 'faithful_data_normalized.png' plt.savefig ( filename ) print ( ' Graphics saved as "%s"' % ( filename ) ) plt.show ( ) plt.clf ( ) # # Terminate. # print ( '' ) print ( 'faithful_data():' ) print ( ' Normal end of execution.' ) return if ( __name__ == '__main__' ): faithful_data ( )