- [screwlisp proposes kittens](../..) # Common Lisp Invoking Gnuplot Straightforward multiple line gnuplot plot using common lisp `uiop`'s (posix-compatibility) `run-program`. Pops up the plot (use the save button). Has a `title`, no `key`, no `xtics`, default `ytics`, no `label`s. Adds tight bounds, where the upper bound is included by adding 1 to it for the limit because I could not think of a sane default. Write a meaningful title. Might be slightly overwrought because gnuplot is a bit confusing. On the other hand this should be straightforward to modify. I chose to use the program invocation for a gnuplot one-liner, and the `run-program` process' input for the data. ## UPDATE Truncates to 1 significant figure at the moment to reconcile the difference between lisp and gnuplot floating point notation. ``` (require "asdf") (defun gnuplot (title &rest x-y-lists) "gnuplot (title &rest x-y-lists) Like (gnuplot \\"Descriptive title\\" '((1 2) (3 4)) '((5 6) (7 8))) Pops up ('persists') the plot. Simple default behaviour. " (let ((cmd (format nil "gnuplot -p -e \\"~ set title '~a'; ~ unset key; ~ unset xtics; ~ set xrange [~,1f:~,1f]; ~ set yrange [~,1f:~,1f]; ~ plot ~{~1*'-' using 1:2 with lines~^,~^ ~};~ \\"" title (apply 'min (mapcar 'car (apply 'append x-y-lists))) (1+ (apply 'max (mapcar 'car (apply 'append x-y-lists)))) (apply 'min (mapcar 'cadr (apply 'append x-y-lists))) (1+ (apply 'max (mapcar 'cadr (apply 'append x-y-lists)))) x-y-lists))) (with-input-from-string (in (format nil "~{~{~{~,1f ~,1f~}~%~}e~^~%~}" x-y-lists)) (uiop:run-program cmd :input in)))) ``` Hope it helps someone. # Example ``` (gnuplot "with a bad title" '((1 2) (3 4)) '((5 6) (7 8))) ;; Or equivalently (apply 'gnuplot "with a bad title" '(((1 2) (3 4)) ((5 6) (7 8)))) ``` # Looking forward to hearing your personal improvements [on the mastodon](https://gamerplus.org/@screwlisp/114545721193969133) I swear, I can't even search engine up the previous demos I personally have written on gnuplot. Do /you/ have an example?