Common Lisp + GNU Plot

So the other day, trying to get a better understanding of the Izhikevich model of spiking neurons, I decided to take apart the .m file that calculates the interactions between one thousand randomly-connected neurons for one thousand milliseconds. Before trying to un-vectorize it and translate it to Lisp, I realized I needed some way to plot the result and  compare it to the Octave one. So I set out to find Common Lisp plotting libaries.

The first one that I tried was CGN, given it was on top of the list and it claimed to connect to GNU Plot. It also uses the LTK, which is the piece of shit (I mean, Tk itself, not the binding which I’m sure involved a lot of hard and honorable work). At least this one had some examples on it, and it loads with Quicklisp. Here’s the Introduction to the manual:

Cgn is a library to control gnuplot from Lisp. Initially thought as simply
a pipe to comunicate with gnuplot, It has grown to provide sintactic sugar
for the most common operations on Gnuplot: plotting graphics, printing,
saving/loading…
Cgn has become big enough to need a manual for itself.

No, it has not. A twelve-page, LaTEX-formatted manual to describe a library so small that the whole of it can be summarized here. Fourteen functions and a macro. The only actual plotting functions are PLOT-FUNCTION and PLOT-POINTS. Then you have a couple handy things like SET-GRID, SET-TITLE, SET-RANGE, but what would be more interesting is a single SET function that takes some arbitrary variable as an argument.

CL-2D I’d heard about before, while shining light into the darkest corners of the Internet, and I sort of liked it. And mind you, it is a nice library, but I had some problems. The example-x11.lisp file worked perfectly, as shown below, but the examples.lisp file gave me some kind of crap about CL-NUMUTILS. I tried ASDF-INSTALL’ing it, but the request meets a 404.

* (ql:Quickload ‘cl-numutils)

debugger invoked on a QUICKLISP-CLIENT::SYSTEM-NOT-FOUND in thread #:
System “cl-numutils” not found

Type HELP for debugger help, or (SB-EXT:QUIT) to exit from SBCL.

restarts (invokable by number or by possibly-abbreviated name):
0: [ABORT] Give up on “cl-numutils”
1: Exit debugger, returning to top level.

((LABELS QUICKLISP-CLIENT::RECURSE) “cl-numutils”)
0] 0

(CL-NUMUTILS)
* (ql:quickload ‘asdf-install)
To load “asdf-install”:
Load 1 ASDF system:
asdf-install
; Loading “asdf-install”

(ASDF-INSTALL)
* (asdf-install:install :cl-numutils)
Install where?
1) System-wide install:
System in /usr/lib/sbcl/site-systems/
Files in /usr/lib/sbcl/site/
2) Personal installation:
System in /home/eudoxia/.sbcl/systems/
Files in /home/eudoxia/.sbcl/site/
–> 2

debugger invoked on a ASDF-INSTALL::DOWNLOAD-ERROR in thread #:
Server responded 404 for GET http://www.cliki.net/CL-NUMUTILS?download

Type HELP for debugger help, or (SB-EXT:QUIT) to exit from SBCL.

restarts (invokable by number or by possibly-abbreviated name):
0: [ABORT] Exit debugger, returning to top level.

(ASDF-INSTALL::DOWNLOAD-FILES-FOR-PACKAGE
“CL-NUMUTILS”
#P”/home/eudoxia/CL-NUMUTILS.asdf-install-tmp”)
0]

CLNUPlot seemed actually rather nice, and I could get it working — To the extent that I could use MAKE-PLOT to create a GNUPLOT object. The WRITE-PLOT function or macro or whatever gave an error about how it could not create the “/plots” folder, so I gave up. I did go through the examples of the cl-plplot library, but I didn’t like it.

So, I decided, I might as well write my own, and the header image at the top of this post shows my current progress. So far the thing is essentially a set of functions (PLOT-FUNCTION, for example) that take some arguments (In the case of PLOT-FUNCTION, string describing the function), concatenate them with other strings to make a functioning command, and pass them to a function called ADD that appends a semicolon at the end, and tosses them into a stack. A finaly function, PLOT, puts everything together and sends it. It’s most certainly not an FFI — Christ, it’s not even a pipe like CGN. It… Well, this is embarassing… It uses trivial shell to send a command, “gnuplot -persist -e (The contents of the stack)”. I’ll make it use a pipe when I know how to. There is also a function, LITERAL-COMMAND that allows you to send a raw string describing a command to GNU Plot and a macro, WITH-GNUPLOT, that holds all the calls to it and at the end calls PLOT, empties the stack, and displays everything. Future features will probably be a function SET that acts on the variables described in a list called SETFABLE-VARIABLES. The quickest approach would be to do something like (set ‘xrange “some string to pass to it”). The SET function would then check the existence of the symbol XRANGE in the SETFABLE-VARIABLES list, and if it’s there, concatenate the strings “set “, a string computed from the symbol (“xrange”), and whatever string argument the user sent. I was thinking of also adding implicit format capabilities, so one could pass a control string and an arbitrary number of arguments to it, which is probably easier than writing a big call to CONCATENATE and stringing any data that you may want to pass. Cutting the dependency on the TRIVIAL-SHELL library would also be good, but first I would need to know how to pipe data to GNU Plot.

This entry was posted in Programming, Projects and tagged , , , , . Bookmark the permalink.

3 Responses to Common Lisp + GNU Plot

  1. Zach Beane says:

    There is no project named cl-numutils, but there is one named cl-num-utils.

  2. Erfan says:

    There is no such thing as GNU Plot. Gnuplot has not even license GPL, you know that?

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 )

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