#! /usr/bin/env python3 # def correlation_heat_map ( ): #*****************************************************************************80 # ## correlation_heat_map() creates a heat map of a correlation matrix. # # Licensing: # # This code is distributed under the MIT license. # # Modified: # # 17 September 2026 # # Author: # # John Burkardt # import matplotlib import numpy as np import platform print ( '' ) print ( 'correlation_heat_map():' ) print ( ' matplotlib version: ' + matplotlib.__version__ ) print ( ' numpy version: ' + np.version.version ) print ( ' python version: ' + platform.python_version ( ) ) print ( ' Heat map of a correlation matrix using gnuplot().' ) # # Set filenames. # header = 'correlation' command_filename = header + '_commands.txt' data_filename = header + '_data.txt' graphic_filename = header + '_heat_map.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 "<--- X --->"\n' ) command_unit.write ( 'set ylabel "<--- Y --->"\n' ) command_unit.write ( 'set title "Heat map of correlation data"\n' ) command_unit.write ( 'set timestamp\n' ) command_unit.write ( 'unset key\n' ) command_unit.write ( 'set tic scale 0\n' ) command_unit.write ( 'set palette rgbformula 21, 22, 23\n' ) cmin = 0.28 cmax = 1.00 command_unit.write ( 'set cbrange[%g:%g]\n' % ( cmin, cmax ) ) command_unit.write ( 'unset cbtics\n' ) xmin = -0.5 xmax = 7.5 ymin = -0.5 ymax = 7.5 command_unit.write ( 'set xrange [%g:%g]\n' % ( xmin, xmax ) ) command_unit.write ( 'set yrange [%g:%g]\n' % ( ymin, ymax ) ) command_unit.write ( 'set size square\n' ) command_unit.write ( 'set view map\n' ) command_unit.write ( 'splot "' + data_filename + '" matrix with image\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 ( ) correlation_heat_map ( ) timestamp ( )