Tuesday 21 July 2015

A quick one-liner for plotting multiple files

I have a series of directories, each with a file of the same name, containing numerical data to do with calculations of nuclear fusion.  Each data set differs by the starting condition, and I'd like to be able to quickly show all the different calculations together, and see a visual update of them all, while my code is generating the files.

A quick one-liner, which does this is


plot for [file in system("ls -1 */qmom")] file u 0:1 w l t file


In this case, the file in each directory is called qmom.  The for loop syntax for [a in list] allows an arbitrary list of text strings to be looped over and assigned to a variable.  This allows for a really quick way to produce a plot comparing data from several files.

Of course, extra commands to prettify the plot to one's taste would probably be needed for a production plot.  The attached plot has had a bit of such stuff done (as well as adding labels etc.)