#! /usr/bin/env python3 # def mark_points ( ): #*****************************************************************************80 # ## mark_points() shows how to add marked points to a plot. # # Discussion: # # You can't add more items to a gnuplot() plot once it's created, # so if you want to plot some points, and then include some markers, # then you have to create some auxilliary data files identifying those # marked points, and refer to them in an extra-long single plot() command. # # Licensing: # # This code is distributed under the MIT license. # # Modified: # # 04 December 2025 # # Author: # # John Burkardt # import matplotlib import numpy as np import platform print ( '' ) print ( 'mark_points():' ) print ( ' matplotlib version: ' + matplotlib.__version__ ) print ( ' numpy version: ' + np.version.version ) print ( ' python version: ' + platform.python_version ( ) ) print ( ' mark_points() plots a damped sine function over a range.' ) print ( ' Mark the first data point green, and the last one red..' ) # # Define the damped_sine data. # rho0 = 1.0 n = 101 rho = np.linspace ( -12.0, +12.0, n ) c = np.ones ( n ) i = np.where ( rho != 0.0 ) c[i] = rho0 * np.sin ( np.abs ( rho[i] ) / rho0 ) / np.abs ( rho[i] ) # # Request a plot # mark_points_plot ( n, rho, c, 'mark_points', 'Marking points in gnuplot' ) return def mark_points_plot ( n, rho, c, header, title ): #*****************************************************************************80 # ## mark_points_plot() adds two marked points to a plot. # # Licensing: # # This code is distributed under the MIT license. # # Modified: # # 02 September 2026 # # Author: # # John Burkardt # # Input: # # integer N, the number of arguments. # # real RHO(N), the arguments. # # real C(N), the correlations. # # string HEADER, an identifier for the files. # # string TITLE, a title for the plot. # # # Create the main data file. # data_filename = header + '_data.txt' data_unit = open ( data_filename, 'wt' ) for i in range ( 0, n ): s = ( ' %14.6g %14.6g\n' % ( rho[i], c[i] ) ) data_unit.write ( s ) data_unit.close ( ) print ( ' Created data file "' + data_filename + '"' ) # # Create a data file for the green point. # start_data_filename = header + '_start_data.txt' data_unit = open ( start_data_filename, 'wt' ) s = ( ' %14.6g %14.6g\n' % ( rho[0], c[0] ) ) data_unit.write ( s ) data_unit.close ( ) print ( ' Created data file "' + start_data_filename + '"' ) # # Create a data file for the red point. # end_data_filename = header + '_end_data.txt' data_unit = open ( end_data_filename, 'wt' ) s = ( ' %14.6g %14.6g\n' % ( rho[n-1], c[n-1] ) ) data_unit.write ( s ) data_unit.close ( ) print ( ' Created data file "' + end_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 "Distance Rho"\n' ) command_unit.write ( 'set ylabel "Correlation C(Rho)"\n' ) command_unit.write ( 'set title "' + title + '"\n' ) command_unit.write ( 'set grid\n' ) command_unit.write ( 'set timestamp\n' ) command_unit.write ( 'set style data lines\n' ) command_unit.write ( 'plot "' + data_filename + \ '" using 1:2 lw 3 linecolor rgb "blue", \\\n' ) command_unit.write ( ' "' + start_data_filename + \ '" using 1:2 with points pointtype 7 pointsize 3 linecolor rgb "green", \\\n' ) command_unit.write ( ' "' + end_data_filename + \ '" using 1:2 with points pointtype 7 pointsize 3 linecolor rgb "red"\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 ( ) mark_points ( ) timestamp ( )