Tag: <span>UNIX</span>

ASCII plotting on the command line terminal with eplot

If you want to plot something on the terminal in ASCII you can use “eplot”.

eplot itself is a Ruby script that acts as a frontend for gnuplot. eplot can be downloaded from the project’s GitHub page. It makes it easier to pipe numbers into gnuplot, which can otherwise be a bit of a hassle. It also has a dumb terminal mode which allows us to plot using ASCII. Plotting like this provides a way to quickly check data files without requiring any x windowing system, which might not be available when logging in remotely over the terminal.

If your computer already has gnuplot and the Ruby runtime installed then the following should work.


cat model.ht | tail -n +2 | awk '{print $1,$2}' | eplot-master/eplot -d -r [0:5]

The -d option chooses ASCII “dumb terminal” mode and -r allows us to set the x axis range.

Some example output:


Now, of course if you want to do the same for a remote file that is possible over ssh.

ssh user@remote.server cat /somepath/model.ht | eplot-master/eplot -d

There are obviously many more options to play around with but I hope this gives a brief introduction to some of the capabilities available.

Cool code: plotting columns from many data files with Grace

Grace a.k.a. xmgrace is a really useful tool for plotting histograms from tabular data files. Its power comes from the command line control and being scriptable. Yes, there are other options which are sometimes more suitable for specific situations (e.g. GNUplot, Matplotlib/PyLab), but for quick, basic plotting I usually find myself relying on xmgrace.

Here is an example of a single line command to plot two columns from each of a large number of data files:

for i in ./a*/field.log; do echo -n " -block $i -bxy 10:44" ; done | xargs xmgrace

The command searches all current subdirectories with names beginning “a” for files called field.log. For each field.log file found it uses an echo command to generate a commandline argument string that we normally use to make a 2D plot with the 10th (x axis) and 44th (y axis) columns using xmgrace. The -n option for echo makes sure there is no newline after each echo, generating one long collection of commands. We next want to pass this on to xmgrace…

xmgrace does not take input from stdin so we first pipe the total echo output to xargs, which is a tool used to construct command line parameters from stdin. xargs then passes these command line arguments to xmgrace.

This little code snippet saves a lot of typing, which grows of the order N for N data files. Now I need to work out how to name each data set on the fly too.