This document is a companion for eazy-gnuplot users going through the 'excellent book by Lee Philips 'gnuplot Cookbook' from Packt Publishing. I highly recommend buying this book.
In this companion we demonstrate implementing the plots in the book using eazy-gnuplot
. Liberties have been taken plots may not follow exactly what is shown in the book (when they don't they follow the spirit).
This document is an iPython notebook from common-lisp-jupyter. Clone eazy-gnuplot or download this notebook at https://github.com/guicho271828/eazy-gnuplot/blob/master/docs/eazy-gnuplot-cookbook-companion.ipynb. Go to the downloaded directory and execute 'jupyter notebook' from a shell.
Edit: Updated the notebook for newer eazy-gnuplot and common-lisp-jupyter (a successor of cl-jupyter that is better maintained). I strongly recommend installation via Roswell (without it, installation is kind of manual). (Masataro Asai)
;png-from-file is used to display png files in cl-jupyter if not using cl-jupyter create a dummy function
(defun png-from-file (f) (jupyter:file f :display t))
PNG-FROM-FILE
;We need a directory called images to store our plots make sure it exists
(ensure-directories-exist "images/")
"images/"
NIL
(quicklisp-client:quickload '(:eazy-gnuplot :clml.statistics :clml.utility))
(use-package :eazy-gnuplot)
To load "eazy-gnuplot": Load 1 ASDF system: eazy-gnuplot ; Loading "eazy-gnuplot" [package lisp-namespace-asd] To load "clml.statistics": Load 1 ASDF system: clml.statistics ; Loading "clml.statistics" [package clml.statistics.rand-environment] To load "clml.utility": Load 1 ASDF system: clml.utility ; Loading "clml.utility" [package drakma-asd].............................. [package flexi-streams-system].................... [package chipz-system]...
(:EAZY-GNUPLOT :CLML.STATISTICS :CLML.UTILITY)
T
(defun function-plot (output)
(with-plots (s :debug nil)
(gp-setup :terminal '(pngcairo) :output output)
(plot "(sin(1/x) - cos(x))*erfc(x)"))
output)
(png-from-file (function-plot "images/function-plot.png"))
FUNCTION-PLOT
SB-INT:SIMPLE-STYLE-WARNING: The variable S is defined but never used.
(defun seperate-y-axis-plot (output)
(with-plots (s :debug nil)
(gp-setup :terminal '(pngcairo) :output output :y2tics '(-100 10) :ytics
:nomirror)
(plot "sin(1/x) axis x1y1,100*cos(x) axis x1y2"))
output)
(png-from-file (seperate-y-axis-plot "images/seperate-y-axis-plot.png"))
SEPERATE-Y-AXIS-PLOT
SB-INT:SIMPLE-STYLE-WARNING: The variable S is defined but never used.
(defun seperate-y-axis2-plot (output)
(with-plots (s :debug nil)
(gp-setup :terminal '(pngcairo) :output output :x2tics '(-20 2) :xtics
:nomirror :xrange '(-10 10) :x2range '(-20 10) :samples
100)
(plot "sin(1/x) axis x1y1")
(plot "100*cos(x-1) axis x2y2"))
output)
(png-from-file (seperate-y-axis2-plot "images/seperate-y-axis2-plot.png"))
SEPERATE-Y-AXIS2-PLOT
SB-INT:SIMPLE-STYLE-WARNING: The variable S is defined but never used.
(defun scatter-plot (output)
(with-plots (s :debug nil)
(gp-setup :terminal '(pngcairo) :output output)
(plot
(lambda ()
(loop for p in (map 'list (lambda (x y) (list x y))
(clml.statistics:rand-n
(clml.statistics:chi-square-distribution 100) 300)
(clml.statistics:rand-n
(clml.statistics:chi-square-distribution 10) 300))
do (format s "~&~{~a~^ ~}" p)))
:with '(:points :pt 7)))
output)
(png-from-file (scatter-plot "images/scatter-plot.png"))
SCATTER-PLOT
(defun plotting-boxes-plot (output)
(with-plots (s :debug nil)
(gp-setup :terminal '(pngcairo) :output output :style '(:fill :pattern))
(plot "[-6:6] besj0(x) with boxes, sin(x) with boxes"))
output)
(png-from-file (plotting-boxes-plot "images/plotting-boxes-plot.png"))
PLOTTING-BOXES-PLOT
SB-INT:SIMPLE-STYLE-WARNING: The variable S is defined but never used.
(defun plotting-boxes-solid-plot (output)
(with-plots (s :debug nil)
(gp-setup :terminal '(pngcairo) :output output :style '(:fill :solid))
(plot "[-6:6] besj0(x) with boxes, sin(x) with boxes"))
output)
(png-from-file
(plotting-boxes-solid-plot "images/plotting-boxes-solid-plot.png"))
PLOTTING-BOXES-SOLID-PLOT
SB-INT:SIMPLE-STYLE-WARNING: The variable S is defined but never used.
(defun plotting-circles-plot (output)
(with-plots (s :debug nil)
(gp-setup :terminal '(pngcairo) :output output)
(plot
(lambda ()
(loop for p in (map 'list (lambda (x y z)
(declare (ignorable z))
(list x y))
(clml.statistics:rand-n
(clml.statistics:chi-square-distribution 100) 300)
(clml.statistics:rand-n
(clml.statistics:chi-square-distribution 10) 300)
(clml.statistics:rand-n
(clml.statistics:chi-square-distribution 1) 300))
do (format s "~&~{~a~^ ~}" p)))
:with '(:circles)))
output)
(png-from-file (plotting-circles-plot "images/plotting-circles-plot.png"))
PLOTTING-CIRCLES-PLOT
(defun drawing-filled-curves-plot (output)
(with-plots (s :debug nil)
(gp-setup :terminal '(pngcairo) :output output :isosamples 1000)
(plot
(lambda ()
(loop for i from 0 upto 50
do (format s "~&~a ~a" i (sin i))))
:with '(:filledcurves :above :y1 = 0.07))
(plot
(lambda ()
(loop for i from 0 upto 50
do (format s "~&~a ~a" i (sin i))))
:with '(:lines)))
output)
(png-from-file
(drawing-filled-curves-plot "images/drawing-filled-curves-plot.png"))
DRAWING-FILLED-CURVES-PLOT