#! /usr/bin/env python3 # def corkscrew_plot3d ( ): #*****************************************************************************80 # ## predator_plot3d() computes and plots some predator/prey data. # # Licensing: # # This code is distributed under the MIT license. # # Modified: # # 30 September 2026 # # Author: # # John Burkardt # import matplotlib import numpy as np import platform print ( '' ) print ( 'predator_plot3d():' ) print ( ' matplotlib version: ' + matplotlib.__version__ ) print ( ' numpy version: ' + np.version.version ) print ( ' python version: ' + platform.python_version ( ) ) print ( ' Model the interaction between rabbits and foxes.' ) header = 'predator' # # Define the data. # n = 1001 t = np.zeros ( n ) pred = np.zeros ( n ) prey = np.zeros ( n ) # # Define the data. # dt = ( 5.0 - 0.0 ) / ( n - 1 ); t[0] = 0.0; prey[0] = 5000.0; pred[0] = 100.0; for i in range ( 1, n ): t[i] = t[i-1] + dt; prey[i] = prey[i-1] + dt * ( 2.0 * prey[i-1] - 0.001 * pred[i-1] * prey[i-1] ); pred[i] = pred[i-1] + dt * ( - 10.0 * pred[i-1] + 0.002 * pred[i-1] * prey[i-1] ); # # Create the data file. # data_filename = header + '_data.txt' data_unit = open ( data_filename, 'wt' ) for i in range ( 0, n ): s = ( ' %14.6g %14.6g %14.6g\n' % ( t[i], pred[i], prey[i] ) ) data_unit.write ( s ) data_unit.close ( ) print ( ' Created data file "' + data_filename + '"' ) # # Create the command file. # command_filename = header + '_commands.txt' command_unit = open ( command_filename, 'wt' ) command_unit.write ( '# ' + command_filename + '\n' ) command_unit.write ( '#\n' ) command_unit.write ( '# Usage:\n' ) command_unit.write ( '# gnuplot < ' + command_filename + '\n' ) command_unit.write ( '#\n' ) command_unit.write ( 'set term png\n' ) command_unit.write ( 'set output "' + header + '.png"\n' ) command_unit.write ( 'set xlabel "Time"\n' ) command_unit.write ( 'set ylabel "Predator"\n' ) command_unit.write ( 'set zlabel "Prey"\n' ) command_unit.write ( 'set title "Predator/prey evolution"\n' ) command_unit.write ( 'set grid\n' ) command_unit.write ( 'set timestamp\n' ) command_unit.write ( 'set style data lines\n' ) command_unit.write ( 'splot "' + data_filename + \ '" using 1:2:3 with lines\n' ) command_unit.write ( 'quit\n' ) command_unit.close ( ) print ( ' Created command file "' + command_filename + '"' ) return def timestamp ( ): #*****************************************************************************80 # ## timestamp() prints the date as a timestamp. # # Licensing: # # This code is distributed under the MIT license. # # Modified: # # 21 August 2019 # # Author: # # John Burkardt # import time t = time.time ( ) print ( time.ctime ( t ) ) return if ( __name__ == '__main__' ): timestamp ( ) corkscrew_plot3d ( ) timestamp ( )