#! /usr/bin/env python3 # def drug_dosage_plots ( ): #*****************************************************************************80 # ## drug_dosage_plots() plots the blood drug levels over time. # # Licensing: # # This code is distributed under the MIT license. # # Modified: # # 24 September 2026 # # Author: # # John Burkardt # import matplotlib import numpy as np import platform print ( '' ) print ( 'drug_dosage_plots():' ) print ( ' numpy version: ' + np.version.version ) print ( ' python version: ' + platform.python_version ( ) ) print ( ' On a single picture, plot:' ) print ( ' * the variation in blood levels of a medicinal drug.' ) print ( ' * the minimal effective level.' ) print ( ' * the toxic level.' ) # # Set filenames. # header = 'drug_dosage' command_filename = header + '_commands.txt' data_filename = header + '_data.txt' graphic_filename = header + '_plots.png' # # Create commands. # 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 "' + graphic_filename + '"\n' ) command_unit.write ( 'set xlabel "<--- Hours --->"\n' ) command_unit.write ( 'set ylabel "<--- Concentration (mg/l) --->"\n' ) command_unit.write ( 'set title "Drug level variation over time"\n' ) command_unit.write ( 'set key on\n' ) command_unit.write ( 'set grid\n' ) command_unit.write ( 'set timestamp\n' ) command_unit.write ( 'set style data lines\n' ) command_unit.write ( 'set yrange [0:1100]\n' ); command_unit.write ( 'plot "' + data_filename + '" using 1:2 with lines lw 3, \\\n' ) command_unit.write ( ' [y=800:800] 0,48 with lines lw 3 lt rgb "green" title "Minimal medicinal level", \\\n' ) command_unit.write ( ' 1000 with lines lw 3 lt rgb "red" title "Toxic level"\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 ( ) drug_dosage_plots ( ) timestamp ( )