---
layout: ../Site.layout.js
---
# Screwlisp's knowledge : common lisp : Simple gnuplot
- - «.intro» (to "intro")
- - «.eev» (to "eev")
- - «.source» (to "source")
- - - «.directories» (to "directories")
- - - «.motivation» (to "motivation")
- - - «.definition» (to "definition")
- - - «.documentation» (to "documentation")
- - - «.default-load» (to "default-load")
- - «.useage» (to "useage")
- - - «.result» (to "result")
- - «.fin» (to "fin")
This eepitch was included in [Edrx's eev knowledge collection](https://anggtwu.net/LISP/2025-may-gnuplot.lisp.html)!
```
(require "asdf")
(asdf:load-system :screwlisps-knowledge/simple-gnuplot)
(use-package :screwlisps-knowledge/simple-gnuplot)
(gnuplot "Of these" '((-1 2) (1 2)) '((3 4) (4 4)) '((-1 2) (4 4)))
```
https://codeberg.org/tfw/screwlisps-knowledge/src/branch/main/simple-gnuplot.lisp
## Intro
- «intro» (to ".intro")
Congealing my earlier [article on common lisp gnuplot](../common-lisp-invoking-gnuplot) into our new [systematic package approach](../crystalizing-lisp-fragments-into-asdf). Bear with me and [feedback on your experience of the useage via the mastodon if you have time](https://gamerplus.org/@screwlisp/114571984754183351).
## eev, common lisp, directory structure and the git
- - «eev» (to ".eev")
[`eev` style is to be transparent if not necessarily unsubtle](http://anggtwu.net/eepitch.html). So
```
(eepitch-shell)
sudo apt install gnuplot
mkdir -p ~/gits
mkdir -p ~/common-lisp
cd ~/gits
git clone ssh://git@codeberg.org/tfw/screwlisps-knowledge.git
cd ~/common-lisp
ln -s ~/gits/screwlisps-knowledge
```
## Source
- «source» (to ".source")
### Set up directories
- - - «directories» (to ".directories")
```
cd ~/common-lisp/screwlisps-knowledge
touch simple-gnuplot.lisp
```
hmmm I'm probably going to regret deciding to use a flat directory structure to ensure uniformity and lack of name collisions.
### Motivation
- - - «motivation» (to ".motivation")
my intent with `simple-gnuplot` is to reduce a great swathe of common graph plotting in lisp to `(apply 'gnuplot "my good title" list more-lists)` (or `(gnuplot 'title ((1 2) (3 4)) ((5 6) (7 8)))` if you prefer). The `apply` form is useful if you have a list of lists you want to plot, but have one or two more lists to optionally add in the middle, similar to the `:keyword` `appy` idiom.
### `~/common-lisp/screwlisps-knowledge/simple-gnuplot.lisp` Definition
- - - «definition» (to ".definition")
```
(uiop:define-package :screwlisps-knowledge/simple-gnuplot
(:mix :asdf :cl)
(:export #:gnuplot))
(in-package :screwlisps-knowledge/simple-gnuplot)
(defun gnuplot (title &rest x-y-lists)
(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)))
(apply 'max (mapcar 'car (apply 'append x-y-lists)))
(apply 'min (mapcar 'cadr (apply 'append x-y-lists)))
(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))))
```
### Documentation
- - - «documentation» (to ".documentation")
add a description
```
(setf (documentation 'gnuplot 'function)
"gnuplot (title &rest lists)
title: Probably a string or symbol describing the otherwise terse graph plot(s).
lists: any number of lists like ((1 2) (3 4) (5 6)) ((7 8) (9 10)) ((11 12)) being (x y) pairs.
invokes gnuplot with lines on all of the lists.")
```
### Load by default
- - - «default-load» (to ".default-load")
and we have to add it to `~/gits/screwlisps-knowledge/all.lisp` as well actually, I guess there is no free lunch.
## Useage
- - «useage» (to ".useage")
```
(require "asdf")
(asdf:load-system :screwlisps-knowledge/simple-gnuplot)
(use-package :screwlisps-knowledge/simple-gnuplot)
(gnuplot "foo bar" '((-1 2) (1 2)) '((3 4) (4 4)) '((-1 2) (4 4)))
```
### Result
- - - «result» (to ".result")
## Fin.
- - «fin» (to ".fin")
Well, it works and I think this works. I am interested in hearing about how easy it was for you to personally use probably on [this Mastodon thread](https://gamerplus.org/@screwlisp/114571984754183351). Show will be live 000UTC Wednesday as every week, watch the Mastodon.