Plotting in Lisp, Part I

In my continuing saga to find the ideal solution for performing machine learning research, I have decided that Common Lisp is probably the way to go. It has the interactive-development approach of MATLAB, integrates extremely well with Emacs, runs with comparable performance to compiled C code, is elegant and powerful, has extremely easy storage of data and program state, and can even do fast linear algebra stuff. The only thing that I feel is lacking is integrated visualization. One of the things that I like about MATLAB enough to usually forgive its hideous development model is the ability to look at plots of data immediately and inline. When I write number-crunching code using Perl or C, I invariably have to dump it all out to file and then use gnuplot to visualize it. Gnuplot does to everything I want, but I don’t like having to leave my nice little development environment to get to it. What I want is to be able to take Lisp data structures and dump them directly into gnuplot on from the REPL. Theoretically, the gnuplot.lisp module in CLOCC does this, but it has been a very frustrating experience for me because I have found it buggy and badly documented. I have not found anyone else who is using it, so there is no example code that I can find. I appreciate that someone else has taken the time to make this available for me to use, but “just look at the source” is not a useful way to address the lack of documentation.

So, I have decided to embark on an open-source development adventure and implement a gnuplot module myself. I intend to make rather heavy use of CLOS, because I think the object-oriented worldview works well in this situation, considering things like “plots” and “data series.” Before I write much more than prototype code, however, I want to decide what the interface should look like. Because of what I happen to be thinking about right at the moment, I am going to consider how I might want to deal with histograms first. I am imagining that my data will look like this:

;; Some data in a list
(defparameter my-data '( 2 4 5 92 1 3 4 ... 2 3))

I would like to view this in a histogram. I am imagining that I’ll want to view the plot using X11 at first and tweak it until I have it looking the way I want, and then create a postscript file. This is pretty much exactly how I use gnuplot now; I just want to be able to do it from the REPL, using my Lisp data structures and Lisp syntax. So, I imagine that I’ll want to create some kind of plot object, with this data attached:

;; Create a histogram plot object with the data
(defparameter my-plot (make-instance 'histogram-plot :data my-data))

This would use some sort of default binning, and have various default parameters. I would expect to wind up with a plot on my screen that stays there until I close it or the my-plot object gets garbage-collected. I would imagine being able to tweak various settings on the graph, and then tell it to replot:

;; Tweak some settings
(set-title my-plot "Histogram of Some Data")
(set-xlabel my-plot "x-axis Label")
(set-ylabel my-plot "y-axis Label")
(replot my-plot)

I have continued this discussion here.

One Response to “Plotting in Lisp, Part I”

  1. Iain

    You might want to look at how octave communicates with gnuplot. I get the impression it’s pretty horrible. I seem to remember it ends up doing stupid things like having to resend huge amounts of data and/or create temporary files.

Leave a Reply

This is a captcha-picture. It is used to prevent mass-access by robots. (see: www.captcha.net)

You must read and type the 5 chars within 0..9 and A..F, and submit the form.

  

Oh no, I cannot read this. Please, generate a