clgplot is a Gnuplot front-end on Common Lisp.
Gnuplot (>4)
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)
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")
(defparameter *x-list* (loop for i from (- pi) to pi by 0.1 collect i))
(clgp:plot (mapcar #'sin *x-list*))
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)
(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)")
(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)))
(clgp:splot (lambda (x y) (+ (sin x) (cos y)))
*x-list* ; x
*x-list* ; y
:view-point '(20 45) :z-scale 1.5)
(clgp:splot (lambda (x y) (+ (sin x) (cos y)))
*x-list* ; x
*x-list* ; y
:map t)
(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)
(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
)
(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))
Satoshi Imai ([email protected])
The MIT license