clgplot

2022-04-01

A Gnuplot front-end for Common lisp

Upstream URL

github.com/masatoi/clgplot

Author

Satoshi Imai

License

MIT Licence,
README

1clgplot

clgplot is a Gnuplot front-end on Common Lisp.

1.1Dependencies

Gnuplot (>4)

1.2Installation

cd ~/quicklisp/local-projects
git clone https://github.com/masatoi/clgplot.git

In case of using Roswell, simply

ros install masatoi/clgplot
(ql:quickload :clgplot)

1.3Usage

clgplot generates a data file and a setting file of Gnuplot to tmp directory and execute Gnuplot with -persist option.Paths to these files or command can be changed as below.
(defparameter clgp:*gnuplot-path* "gnuplot")
(defparameter clgp:*tmp-dat-file* "/tmp/clgplot-tmp.dat")
(defparameter clgp:*tmp-gp-file* "/tmp/clgplot-tmp.gp")

1.3.1Plot of single function

(defparameter *x-list* (loop for i from (- pi) to pi by 0.1 collect i))

(clgp:plot (mapcar #'sin *x-list*))

./docs/img/clgp01.png

Plots can be output to a file as follows.

(clgp:plot (mapcar #'sin *x-list*) :output "/path/to/file.png")
(clgp:plot (mapcar #'sin *x-list*) :output "/path/to/file.png" :output-format :png)
(clgp:plot (mapcar #'sin *x-list*) :output "/path/to/file.pdf" :output-format :pdf)
(clgp:plot (mapcar #'sin *x-list*) :output "/path/to/file.eps" :output-format :eps)

1.3.2Plot of multiple functions with annotations

(clgp:plots (list (mapcar #'sin *x-list*)
                  (mapcar #'cos *x-list*)
                  (mapcar #'tan *x-list*))
            :x-seqs  (list *x-list* *x-list* *x-list*)
            :x-range (list (- pi) pi)
            :y-range '(-1 1)
            :title-list '("sin" "cos" "tan")
            :x-label "x"
            :y-label "f(x)")

./docs/img/clgp02.png

(let* ((rand-x-list (loop repeat 100 collect (- (random (* 2 pi)) pi)))
       (rand-y-list (mapcar (lambda (x) (+ (sin x) (random-normal :sd 0.1d0))) rand-x-list)))
  (clgp:plots (list (mapcar #'sin *x-list*)
                    rand-y-list)
              :x-seqs (list *x-list* rand-x-list)
              :style '(line point)))

./docs/img/clgp02-2.png

1.3.33D plot examples

(clgp:splot (lambda (x y) (+ (sin x) (cos y)))
  *x-list* ; x
  *x-list* ; y
  :view-point '(20 45) :z-scale 1.5)

./docs/img/clgp03.png

(clgp:splot (lambda (x y) (+ (sin x) (cos y)))
  *x-list* ; x
  *x-list* ; y
  :map t)

./docs/img/clgp04.png

1.3.4Plot matrix (2-dimensional array)

(defparameter mat
  (make-array '(20 20)
              :initial-contents
              (loop for i from (- pi) to (- pi 0.1) by (/ pi 10) collect
                (loop for j from (- pi) to (- pi 0.1) by (/ pi 10) collect
                  (+ (sin i) (cos j))))))

(clgp:splot-matrix mat)

./docs/img/clgp05.png

1.3.5Histogram

(defun random-normal (&key (mean 0d0) (sd 1d0))
  (let ((alpha (random 1.0d0))
	(beta  (random 1.0d0)))
    (+ (* sd
	  (sqrt (* -2 (log alpha)))
	  (sin (* 2 pi beta)))
       mean)))

(clgp:plot-histogram (loop repeat 3000 collect (random-normal)) ; samples
                     30 ; number of bin
                     )

./docs/img/clgp06.png

1.3.6Multiplot

(clgp:multiplot (:layout (2 2) :output "/tmp/multiplot.png" :output-format :png)
  (clgp:plot (mapcar #'sin *x-list*) :style 'lines :key nil)
  (clgp:plot (mapcar #'sin *x-list*) :style 'points :key nil)
  (clgp:plot (mapcar #'sin *x-list*) :style 'impulses :key nil)
  (clgp:plots (list (mapcar #'sin *x-list*)
                    (mapcar #'cos *x-list*)
                    (mapcar #'tan *x-list*))
              :x-seqs  (list *x-list* *x-list* *x-list*)
              :x-range (list (- pi) pi)
              :y-range '(-1 1)
              :key nil))

./docs/img/multiplot.png

1.4Author

Satoshi Imai (satoshi.imai@gmail.com)

1.5License

The MIT license

Dependencies (3)

  • iterate
  • prove
  • uiop

Dependents (0)

    • GitHub
    • Quicklisp