Plotting from the command line — a new version of ‘graph’

2020-12-22 at 11:23 pm Leave a comment

I’ve forked the GNU ‘plotutils’ package, written mostly by Rob Maier, which contains the ‘graph’ program. I’ve added new features to ‘graph’ to make it a better tool for producing plots from the Linux/Unix/macOS command line.

My main motivation is to use it with my Software for Flexible Bayesian Modeling (FBM), which consists of a set of programs to be run from the command line. One crucial FBM program is ‘net-plt’, which displays information from a log file for an MCMC run of a Bayesian neural network model. Here’s an example use of ‘graph’ to display the average squared error on training and test cases with networks from an MCMC run that is used as an example in the FBM documentation:

net-plt t bB rlog.net | graph -n

And here is the resulting plot:

The ‘net-plt’ command produces two series of values — ‘b’ values are squared error on the training set, and ‘B’ values are squared error on the test set — with both plotted against ‘t’, the MCMC iteration index. The ‘graph’ program plots both series, in different colours (colurs cycle through red, green, blue, magenta, cyan).

The ‘-n’ option for ‘graph’ enables my new set of defaults for getting nice-looking plots. For comparison, here is the plot produced with ‘graph’ from the last GNU release (plututils-2.6, from 2009, with minor fixes to make it work now), using the old default options:

The huge margins with the old defaults waste a lot of space. Not using colour by default also makes the plot much less appealing (and less intelligible). If you look closely, you can see some other changes I made. There are further changes not visible here that make the now smaller margins work better (e.g., when big numbers are displayed in scientific notation).

You also can’t see the changes that make the interaction go more smoothly. With my new defaults, the ‘graph’ program will display the plot and then wait until the user either closes the plot window or terminates the ‘graph’ program by typing Control-C. This way, one can quickly look at various plots with a succession of commands (often just editing the previous command slightly, with the shell’s command editing facilities). Of course, you can keep a window up by just putting the command in the background (e.g,, with ‘&’ at the end).

The old version of ‘graph’ quit after putting up the plot window, which then had to be removed by clicking in it or typing ‘q’ (both of which could easily be done accidentally if you wanted to keep it).  The mouse focus moved away from the window where commands are typed, so you had to move the mouse to get it back before typing the next command.

Some further improvements can be seen with this command to display the values of three hyperparameters at each MCMC iteration:

net-plt t h1h2h3 rlog.net | graph -n -p2 -ly -gy

These hyperparameters are the prior standard deviations of weights from network inputs to hidden units, of hidden unit biases, and of weights from hidden units to the network output. The ‘-ly’ option makes the vertical scale be logarithmic. The ‘-gy’ option adds horizontal (but not vertical) grid lines (with the old version of ‘graph’ you got both or neither). The ‘-p2’ option produces a point plot with medium-size points; it is an abbreviation I added, equivalent to ‘-S16 0.02 -m-1’ with the old version of ‘graph’.

I’ve previously used the ‘xgraph’ program, written over 20 years ago by David Harrison. But it shows its age, not really working correctly when you do things like change the window size (though it used to work fine). The ‘graph’ program (and the ‘plotutils’ package it is part of) are also not well-maintained — the last GNU update was in 2009 — but the code seems in better shape than ‘xgraph’. I hope I’ve managed to get most of the advantages of ‘xgraph’ into the new version of  ‘graph’, and that it will serve for years to come. (I might even add some more features…)

You can get my new version of ‘plotutils’ and ‘graph’ from the source repository at

http://github.com/radfordneal/plotutils/tree/plotutils+-3.1

You’ll need to build it from source, so you will need a C compiler and other development tools. If you have them, you should be able to download the zip file (using the green ‘Code’ button), unzip it, and in the directory it creates, use the commands:

./configure
make

If this works, the graph program will be ‘graph’ in the ‘graph’ sub-directory. You may want to copy it somewhere more convenient, and perhaps make an alias or shell script to invoke it with ‘-n’.

You may also want to read the README, NEWS, INSTALL, and INSTALL.pkg files.

Entry filed under: Computing, Statistics, Statistics - Nontechnical.

New version of pqR, with automatic differentiation and arithmetic on lists

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Trackback this post  |  Subscribe to the comments via RSS Feed


Calendar

December 2020
M T W T F S S
 123456
78910111213
14151617181920
21222324252627
28293031  

Most Recent Posts


%d bloggers like this: