masatoi / clgplot

A Gnuplot front-end for Common lisp
MIT License
29 stars 2 forks source link

** Dependencies Gnuplot (>4)

** Installation

+BEGIN_SRC sh

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

+END_SRC

In case of using Roswell, simply

+BEGIN_SRC sh

ros install masatoi/clgplot

+END_SRC

+BEGIN_SRC lisp

(ql:quickload :clgplot)

+END_SRC

** Usage 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.

+BEGIN_SRC lisp

(defparameter clgp:gnuplot-path "gnuplot") (defparameter clgp:tmp-dat-file "/tmp/clgplot-tmp.dat") (defparameter clgp:tmp-gp-file "/tmp/clgplot-tmp.gp")

+END_SRC

*** Plot of single function

+BEGIN_SRC lisp

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

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

+END_SRC

[[./docs/img/clgp01.png]]

Plots can be output to a file as follows.

+begin_src lisp

(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)

+end_src

*** Plot of multiple functions with annotations

+BEGIN_SRC lisp

(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)")

+END_SRC

[[./docs/img/clgp02.png]]

+begin_src lisp

(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)))

+end_src

[[./docs/img/clgp02-2.png]]

*** 3D plot examples

+BEGIN_SRC lisp

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

+END_SRC

[[./docs/img/clgp03.png]]

+BEGIN_SRC lisp

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

+END_SRC

[[./docs/img/clgp04.png]]

*** Plot matrix (2-dimensional array)

+begin_src lisp

(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)

+end_src

[[./docs/img/clgp05.png]]

*** Histogram

+begin_src lisp

(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 )

+end_src

[[./docs/img/clgp06.png]]

*** Multiplot

+begin_src lisp

(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))

+end_src

[[./docs/img/multiplot.png]]

** Author Satoshi Imai (satoshi.imai@gmail.com)

** License The MIT license