The Python Script "PLOT-files.py"

by Pasquale Pavone

Purpose: The python script PLOT-files.py is employed for producing plots of data included in different files in different directories. Here, we detail how this script works.

General description:

PLOT-files.py can be used basically to plot data from one or more files in the same directory or in different ones. The script generates the PNG output PLOT.png. The different cases are triggered by a series of required and optional arguments, which are described in the following.

Mandatory argument:

Argument Shortcut Default Description
--files -f (mandatory) List of file names containing data to plot. At least one file must be specified.

Optional arguments:

Argument Shortcut Default Description
--help -h Show the help message and exit.
--directory -d './' List of the directories in which the data to be plotted have to be found. If only one or no directory is specified, the data for the plots are taken from the same directory.
--xboundary -x One or two floats corresponding to the minimum and maximum x value in the plot.
--yboundary -y One or two floats corresponding to the minimum and maximum y value in the plot.
--label_x -lx 'x [x]' A string corresponding to the x label.
--label_y -ly 'y [y]' A string corresponding to the y label.
--column_x -cx 1 List of integer values, each of them specifying the number of the text column in the corresponding file from which the x values must be read. If the value '0' is given, a running natural index is considered as x value.
--column_y -cy 2 List of integer values, each of them specifying the number of the text column in the corresponding file from which the y values must be read.
--scale_box -s 1.0 1.0 One or two floats corresponding to the scaling factor in the horizontal and vertical size of the plot appearence, respectively.
--x_scale -xs 1.0 A float corresponding to a scaling factor for the x values.
--y_scale -ys 1.0 A float corresponding to a scaling factor for the y values.
--legend_label -ll Specifies the labels to appear in the legend for each plot.
--legend_position -lp 'best' The location of the legend. The strings 'upper left', 'upper right', 'lower left', 'lower right' place the legend at the corresponding corner of the axes/figure. The strings 'upper center', 'lower center', 'center left', 'center right' place the legend at the center of the corresponding edge of the axes/figure. The string 'center' places the legend at the center of the axes/figure. The string 'best' places the legend at the location, among the nine locations defined so far, with the minimum overlap with other drawn artists. This option can be quite slow for plots with large amounts of data; your plotting speed may benefit from providing a specific location. For back-compatibility, 'center right' (but no other location) can also be spelled 'right', and each string locations can also be given as the corresponding numeric value (see here for more details).
--title -t mmmmmmm Used as --title 'String as a title' assign a title to the plot.
--no_title -nt If present, it disables the writing of the title.
--no_legend -nl If present, it disables the plotting of the legend.
--grid -g If present, a grid is plotted in correspondence to the position of the major ticks.
--reverse_colors -rc If present, the order of the sequence of colors of the plots is reversed.
--reverse_plots -rp If present, the order of appearance of the plots is reversed.
--print_markers -pm If present, solid circle markers are additionally printed for indicating data points.
--max_ticks_x -mtx Specifies the maximum number of ticks along the x-axis in the plot.
--max_ticks_y -mty Specifies the maximum number of ticks along the y-axis in the plot.
--no_scientific -ns If present, disables the scientific notation and the offset for labels on the axes.

Examples:


☛ Plot from different files in the same directory:
$ PLOT-files.py -d DIR1  -f FILE1 FILE2 FILE3 FILE4

☛ Plot from the same file in different directories:
$ PLOT-files.py -f FILE1  -d DIR1 DIR2 DIR3 DIR4

☛ Plot the column m as a function of column n in the same file:
$ PLOT-files.py -f FILE  -cx n  -cy m

☛ Plot the columns n and m in a file in the current directory as a function of the column k in the same file:
$ PLOT-files.py -f FILE FILE  -cx k k  -cy n m

☛ Plot from file FILE in the directory DIR with x-label XLABEL and y-label YLABEL:
$ PLOT-files.py -f FILE  -d DIR  -lx XLABEL  -ly YLABEL

☛ Plot from file FILE containing only one column of data as a function of a running index:
$ PLOT-files.py -f FILE  -cx 0  -cy 1
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License