opening it up with Common Lisp

Favorite weblogs

Lisp Related

Bill Clementson

Finding Lisp


Planet Lisp



Talking Points Memo

This Modern World

Working for Change

Other home


Recent Readings

Book review: Darwinia
Reviewed: Friday, August 11, 2006

Summer reading: Spin
Reviewed: Saturday, August 5, 2006

Reviewed: Tuesday, July 18, 2006

the Omnivoire's Delimma
Reviewed: Wednesday, July 12, 2006

the Golem's Eye
Reviewed: Wednesday, May 31, 2006


Plotting and Lisp: clnuplot
Wednesday, July 20, 2005

I just ran across Ryan Adam’s work on Plotting in Lisp (parts one, two and three) on Lemonodor. Coincidently enough, it turns out that I started working on something similar a few months ago. I called in clnuplot. Which has, I think, a nice ring to it.

From Ryan’s posts, I think we’re approaching the problem from a similar angle. Here are a few notes from two months ago:

I’ve been slowly learning bits and pieces of GNUplot and writing Lisp code to generate data and command files for it. Today (17 May 2005) I spent a bit of time consolidating what I have into something that might be slightly more generally useful.

You can use GNUPlot by writing data files and running plots from the GNUPlot command line or by writing data files and command files and running those or by writing command files that have the data inline. What I’ve done is written some classes and functions that let you manipulate plots in Lisp and then write out a command file that can executed in GNUPlot.

The basic model is one of plots and data-sets. A plot contains information for the entire information display; for example, the title, the axis labels and so forth. Each data set contains information about how to display a single group of data in some format; e.g., the data, the display style, the name of the data in the legend and so forth. A plot contains one or data sets.


  • make-plot &rest args &key name comment filename plot

    If you do not supply a plot argument, this creates a new plot object that contains a single data set. If you do supply the plot argument, the data set and it’s information will be added to it.

  • For example, I have a command that first calls make-plot with not data: :

    (make-plot nil nil 
            :title "Error rate versus F-measure"
            :xlabel "Percent Mixing"
            :ylabel "F-Measure"))

    and then later uses the returned plot to build up a number of data-sets: :

    (make-plot :points data
            :legend (format nil "Negative ~,2F; Positive ~,2F" 
                                (getf key :fnr) (getf key :fpr))
            :x-coord (lambda (x) (getf x :pm))
            :y-coord (lambda (x) (getf x :f))
            :plot plot)

    The final plot object returned contains a whole bunch of data sets. Make-plot currently supports :line, :points and :bar styles. Plots can have titles, a label on the x-axis and the y-axis and custom labels for the legend. Much of the rest of the functionality of GNUplot is missing but the framework is in place to add it pretty easily (I thinkÔ I’ll be adding stuff as I need it). Look in the parameters *plot-plot-settings* and *plot-data-set-settings* to get a sense of what setting the plot code knows about.

  • write-plot plot destination

    This command writes the plot object to its file. Each plot object specifies a host, fullpath (directory) and filename. The host and directory default to *plot-default-host* and *plot-default-directory*. The filename will default to “plot”

    When you call write-plot it will return the pathname to which the file is written. The file can be executed in GNUPlot (either by piping it from the command line (note bene, I haven’t tried this yet myself) or by using the load command in GNUPlot). The plot commands and data will all be included in this single file.

I do most in Macintosh Common Lisp and use Alexander Repenning’s AppleScript support under OS X to call out to the shell — it seems creaky but works surprisingly well! Once I got the basics in place, I’ve not had much time to add the obvious features (or even to publicize my work until today’s goad came along (thank John)). In any case, I couldn’t find Ryan’s e-mail on his blog so if anyone can put us in touch, it would be great to move forward on this together.


Home | About | Quotes | Recent | Archives

Copyright -- Gary Warren King, 2004 - 2006