eazy-gnuplot
2022-04-01
An intuitive CL interface to gnuplot.
1Eazy-Gnuplot
Lispy Gnuplot library
- Structure-less -- no CFFI, no CLOS, no STRUCTURE
- Just print the data to the
*standard-output*
insideplot
function
News
- [Oct 2015] Supports a single datafile with multiple
:using
options. Plotting made more efficient. - Supports for Multiplot environment partially available.
- When :terminal is missing, eazy-gnuplot tries to guess its terminal type from the given pathname.
- Growing the list of interfaces available as functions. Still, "unsupported commands" can be directly printed to the stream.
- Fitting function now available.
- Most arguments supports list notation. e.g. not only `:using '(1 2)` butalso `:errors`, `:via`, `:size`, `m?[xyzr]2?(range|tics)` ...
- [Feb 2016] PLOT function accepts strings (treated as functions) and pathnames (treated as datafile). func-plot and datafile-plot are deprecated (but still available).
- [Mar 2022] More arguments support list notation, e.g., `:first :second :graph :screen :character`
1.1Library Usage
Write 1 with-plots
and (at least) 1 gp-setup
per output file.
gp-setup
accepts and sets any attributes -- mighty
&allow-other-keys
. no compatibility issue re: different gnuplot!.
For more examples, see the eazy-gnuplot cookbook !
;;; when :debug is non-nil, gnuplot code is copied to *trace-output*
(with-plots (s :debug t)
(gp-setup :xlabel "x-label" ; strings : "\"x-label\""
:ylabel "y-label"
:output #p"sample.png" ; pathnames : "\"sample.png\""
:terminal :png ; keyword/symbols: "terminal png"
;; list contents are recursively quoted, then joined by a space
:key '(:bottom :right :font "Times New Roman, 6")
:pointsize "0.4px"
:yrange :|[0:1]|
;; currently, specifying these kinds of options requires to abuse
;; keywords and symbols. Another example: comma separated list, e.g.,
;; :terminal '(:png :size |10cm,6cm|)
;;
;; 2/4/2016 Major options are now covered.
)
;; any unsupported commands are available by printing it to the stream
(format s "~%unset key")
;; or through `gp` command
(gp :unset :key)
;; gp-set and gp-unset are equivalent
(gp-unset :key)
;; to force something to be printed verbatim inside a command, use symbols whose names are escaped with ||
(gp :set :xrange '|[0:1]|)
;; Functions
(plot "sin(x)" :title "super sin curve!")
;; Plot data
(plot #p"data.csv" :title "super sin curve!")
;; Plot a lisp data directly
(plot (lambda ()
(format s "~&0 0")
(format s "~&1 1"))
:using '(1 2)
:title "1"
:with '(:linespoint))
(plot (lambda ()
(format s "~&0 1")
(format s "~&1 0"))
:using '(1 2)
:title "2"
:with '(:lines)))
It results in the following png:
1.2From the Command Line
Requirements: Install roswell.
PATH+=~/.roswell/bin/ ros install eazy-gnuplot plot-init myplot.ros
1.3How it works
Above code This produces the following gnuplot code internally. It will then be fed into gnuplot interpreter.
set xlabel "x-label"
set ylabel "y-label"
set output "sample.png"
set terminal png
set key bottom right font "Times New Roman, 6"
set pointsize "0.4px"
plot sin(x) title "super sin curve!", '-' using 1:2 title "1" with linespoint, '-' using 1:2 title "2" with lines
0 0
1 1
end
0 1
1 0
end
When the script contains some error and gnuplot finishes with non-zero value, it signals UIOP:SUBPROCESS-ERROR .
2Advanced Usage
2.1Use the GUI terminals e.g. WXT, QT
You can even try a wxt terminal or qt terminal and see the GUI interactively.
(eazy-gnuplot:with-plots (*standard-output* :debug t)
(eazy-gnuplot:gp-setup :terminal '(:qt))
(eazy-gnuplot:plot (lambda ()
(format t "~&~A ~A" 1 2)
(format t "~&~A ~A" 2 5)
(format t "~&~A ~A" 3 4)))
(format t "~&pause mouse button1;~%"))
However, these options may not be available on older versions of gnuplot. QT terminal is supported from gnuplot-4.6. WXT terminal has a known bug which leaves a zombie process until gnuplot-4.6.
2.2Dependencies
This library is at least tested on implementation listed below:
- SBCL 1.2.1 on X86-64 Linux 3.13.0-39-generic (author's environment)
Also, it depends on the following libraries:
- ITERATE by
- Jonathan Amsterdam's iterator/gatherer/accumulator facility
- OPTIMA by Tomohiro Matsuyama
- Optimized Pattern Matching Library
- ALEXANDRIA by
- Alexandria is a collection of portable public domain utilities.
2.3Author
- Masataro Asai
3Copyright
LLGPL