#! /usr/bin/env python3 # def corkscrew_plot3d ( ): #*****************************************************************************80 # ## corkscrew_plot3d() plots a 3D corkscrew function. # # Licensing: # # This code is distributed under the MIT license. # # Modified: # # 27 September 2026 # # Author: # # John Burkardt # import matplotlib import numpy as np import platform print ( '' ) print ( 'corkscrew_plot3d():' ) print ( ' matplotlib version: ' + matplotlib.__version__ ) print ( ' numpy version: ' + np.version.version ) print ( ' python version: ' + platform.python_version ( ) ) print ( ' Define (X,Y,Z) data on a 3D curve.' ) header = 'corkscrew' # # Define the data. # n = 101 z = np.linspace ( -2.0, 2.0, n ) theta_min = - 6.0 * np.pi theta_max = + 6.0 * np.pi theta = np.linspace ( theta_min, theta_max, n ) r = 1.0 + z**2 x = r * np.sin ( theta ) y = r * np.cos ( theta ) # # 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' % ( x[i], y[i], z[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 "X"\n' ) command_unit.write ( 'set ylabel "Y"\n' ) command_unit.write ( 'set zlabel "Z"\n' ) command_unit.write ( 'set title "Corkscrew curve"\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 ( )