guicho271828 / eazy-gnuplot

Super Duper Doopa Booka Lispy Gnuplot library
http://guicho271828.github.io/eazy-gnuplot/
63 stars 8 forks source link

Lispy Gnuplot library

News

** Library 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 [[http://guicho271828.github.io/eazy-gnuplot/][eazy-gnuplot cookbook]] !

+BEGIN_SRC lisp

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

+END_SRC

It results in the following png:

[[https://raw.githubusercontent.com/guicho271828/eazy-gnuplot/master/sample.png]]

** From the Command Line

Requirements: Install [[https://github.com/roswell/roswell/wiki/1.-Installation][roswell]].

: PATH+=~/.roswell/bin/ : ros install eazy-gnuplot : plot-init myplot.ros :

** How it works

Above code This produces the following gnuplot code internally. It will then be fed into gnuplot interpreter.

+BEGIN_SRC gnuplot

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

+END_SRC

When the script contains some error and gnuplot finishes with non-zero value, it signals UIOP:SUBPROCESS-ERROR .

** Use the GUI terminals e.g. WXT, QT

You can even try a wxt terminal or qt terminal and see the GUI interactively.

+BEGIN_SRC lisp

(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;~%"))

+END_SRC

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.

** Dependencies

This library is at least tested on implementation listed below:

Also, it depends on the following libraries:

** Author

LLGPL