cgn
cgn is an interface to the gnuplot plotting library. It has been programmed using LTK, and works everywhere LTK works. I has been tested succesfully on Linux and Windows.

I've moved to http://common-lisp.net/project/nixies due to problemes with sourceforge's inferno.

---------------------------------------------

Since cgn007, the prefered way to use cgn should be using the with-gnuplot macro. This way always there's a gnuplot connection running, and you can use a gnuplot which is not at the path. See a little example (more examples on the project web at common-lisp.net ):

(with-gnuplot ( 'linux )

   (plot-function "cos(x)*sin(x)**2" )

   (set-range 'x 0 10)

   (set-range 'y -5 5)

   (set-grid 'on)

   (set-grid 'off)

   (set-title "My graphic")

   ;Plots a scatter graphic with xy errobars


   (plot-points '(1 2 3) '(2 4 5) :x_error '(0.1 0.2 0.3) :y_error '(0.2 0.4 0.5))

   ;You can save a postscript copy of the graphic

   (postscript-copy "file.ps" )

   ;Now you can print you graphics
   (print-graphic )

   ;And finally we save the session
   (save-cgn "MySession.cgn" )
)

It will ever be possible to use the more interactive approach used before :

(start-gnuplot :path "the path to gnuplot")

;Code here

(close-gnuplot)

But cgn will not be sure that a gnuplot connection exists. But It still will give you a error if that does not exists. Get fun!


There is some kind of need for introducing 'finish when using with-gnuplot, which doesn't make any sense to me. It looks like cgn is trying to stop gnuplot from quiting immediately after plotting, which is the default behavior. It does this by a call to read. I think a better solution is to remove the commands (format ...) and (read), add the -persist command line option when gnuplot starts, i.e. change (do-execute path nil) to (do-execute path '("-persist")) up in (defun cgn:start-gnuplot... Seems to do the trick nicely. --Zach

Thanks you. I corrected that error yesterday. --Felip

I found another error. Gnuplot does not understand floating point numbers of the type 9.23d-3. It only understands numbers like 1.234 or 5 or 3.2e-5. However, Gnuplot is quite robust and will try to plot these numbers by dropping the d and it's exponent. This means that 9.23d-3 will be plotted at 9.23. To fix this, go to the plot points function (and where ever else it is needed) and substitute ~D (for decimal printing) to ~F for fixed point numbers. But this is actually not perfect as it is kind of stupid to write out that 300 zeros for something like 1d-300. --Zach

I never tried to use those numbers with gnuplot. Simply, they doesn't make sense to me, since I always prefer to change the units system in my computations before using bigger numbers. But I'll include this too. --Felip

With regards to the above, if you use the format directive ~,,,,,,'EE in place of ~D, you will get a floating point representation of double or single floats but using 'E' as the exponent signifier. All those commas are because the ~E directive accepts something like 7 arguments, the 7th one being the character to use to represent the exponent; those commas separate the arguments that would be their if they were non-nil. See http://www.cs.cmu.edu/Groups/AI/html/cltl/clm/node200.html --Kyle

Also, there seems to be some problem with the .cgn.dat file not being overwritten. Not sure why...

That's not a problem at all. I want cgn 009 to use only pipes, not files. Actually I'm too busy for an immediate release, but I'm planning to do that. But some lisp implementations do buggy things with files. I had that problem last year with clisp on windows. --Felip

Spotted something, when the .cgn.dat file is opened, the arguments ':if-exists :overwrite' are given to with-open-file; meaning that if subsequent data sets are not as long as previous ones, there will still be remnants of the old data left. If this is changed to ':if-exists :supersede' then the old file is wholly replaced by the new file. Also, if anyone is getting junk data being added to a plot on zooming with gnuplot 4.6, gnuplot 4.7 solves this (but you will probs have to build it yourself). --Kyle

There are more things in cgn 008 to change. Example: the os parameter in with-gnuplot. You can use member to see if *features* includes :win32. cgn 009 will do that. I also plan to change the scatter plotting function to do things funcionally. But now I'm very busy. And well, cgn began as a 10 minutes hack to show to a friend the power of lisp. I believe that works pretty well, and I try to document it as well as I can. But It will always be something to start a connection, do some plots and close a connection. There are more sofisticated approaches out there, using threads and those things. I want cgn to be simple. But bug reports are welcome. --Felip

Hello again:

I uploaded cgn008b to sourceforge. It isn't at common-lisp.net because there are things from cgn009 mixed with the correction to those bugs. I didn't want to confuss anyone. You can download at sourceforge. asdf-install will keep installing cgn008. Please, install manually cgn008b only if you need urgently those bugs corrected. --Felip


To download the latest development version of cgn, use darcs get http://common-lisp.net/project/nixies/darcs/cgn. Feel free to send patches to superratoli@gmail.com. You can also get a development snapshot of cgn at http://common-lisp.net/project/nixies/cgn_snapshot.tar.gz

Please, be patient if something doesn't work. This is the main repository for development.


How to do It work on Windows:

---------------------------

Since cgn007, It does not need tuning for working on windows. Just use with-gnuplot ( 'w32 :path "the path to pgnuplot.exe" ) (there's a little example at cgn's web ) . But here you have instructions to put gnuplot at the path.

First of all, you need to install gnuplot, of course. Then, add the directory where you installed It to the path. You can do It by clicking the left button on "My computer" , then "Advanced Options" and "Environment variables". Modify the path variable to add the directory. E.g. : if you installed gnuplot at c:\gnuplot, your path variable must be "c:\program files [more things] ; c:\gnuplot".

Then, go to the directory where gnuplot is installed and rename pgnuplot.exe to gnuplot.exe. That's all!

----------------------------

cgn005 had a hard time compiling on SBCL with my experience (Fedora Core 5 in the US). I suspect the "special" characters in the comments for the function definitions were throwing things off. I deleted all the comments and SBCL seemed a lot happier with things.

Thank you! I've released today (8-VI) cgn006. This is a bug fix only release. I've translated those comments to english, corrected a bug on closing gnuplot and added cldoc documentation at the doc/ directory. It compiles on 0:00:01 on my SBCL 0.9.13 Mandriva Linux in Spain.

Quick assessment (2024-03-10)

Tested with CCL on Windows 11:

(with-gnuplot (:os 'w32 :path "c:/gnuplot/bin/gnuplot.exe") (format-gnuplot "set terminal pngcairo size 480,360 ~ color enhanced font 'Verdana,10'") (format-gnuplot "set encoding utf8") (format-gnuplot "set output 'sin-cos.png'") (format-gnuplot "set xrange[-2*pi:2*pi]") (format-gnuplot "set yrange[-1.5:1.5]") (format-gnuplot "set ytics 1~%set tics scale 0.75") (format-gnuplot "set xtics (\"-2π\" -2*pi, \"\" -pi, 0, \"π\" pi, \"\" 2*pi)") (format-gnuplot "set style line 1 linecolor rgb '#0060ad' linetype 1 linewidth 1") (format-gnuplot "set style line 2 linecolor rgb '#dd181f' linetype 1 linewidth 1") (format-gnuplot "plot sin(x) title 'sin(x)' with lines linestyle 1, ~ cos(x) title 'cos(x)' with lines linestyle 2"))

The above code results in this PNG image:

Combined plot of sin(x) with cos(x)

Important aside:

  • Beware that on Windows, ccl:run-program won't signal an error when the program doesn't start.
  • Which means that ltk:do-execute will not notice a problem if the gnuplot executable isn't found.
  • So there won't be any error until you actually attempt to write to the pipe representing the process.


GPL