ec9067ea1894

Allow gnuplot to take alists
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Sun, 23 May 2021 16:51:40 -0400
parents 25d07c157495
children acf6a1d4de2e
branches/tags (none)
files src/gnuplot.lisp src/iterate.lisp

Changes

--- a/src/gnuplot.lisp	Sun May 23 16:43:03 2021 -0400
+++ b/src/gnuplot.lisp	Sun May 23 16:51:40 2021 -0400
@@ -23,6 +23,13 @@
              (terpri s))
        sequence))
 
+(defun gnuplot-data-alist% (alist s)
+  (loop :for (k . v) :in alist :do
+        (princ k s)
+        (princ #\tab s)
+        (princ v s)
+        (terpri s)))
+
 (defun gnuplot-data-matrix% (matrix s)
   (destructuring-bind (rows cols) (array-dimensions matrix)
     (dotimes (r rows)
@@ -36,7 +43,8 @@
 
   `identifier` must be a string of the form `$foo`.
 
-  `data` must be a sequence of sequences of data or a 2D array of data.
+  `data` must be one of the following: a sequence of sequences of data points,
+  an alist of data points, or a 2D array of data points.
 
   Must be called from inside `with-gnuplot`.
 
@@ -47,6 +55,7 @@
   (format s "~A << EOD~%" identifier)
   (etypecase data
     ((array * (* *)) (gnuplot-data-matrix% data s))
+    ((cons (cons t (not cons))) (gnuplot-data-alist% data s))
     (sequence (gnuplot-data-sequence% data s)))
   (format s "EOD~%"))
 
@@ -72,9 +81,11 @@
 (defun gnuplot (data commands)
   "Graph `data` with gnuplot using `commands`.
 
-  `data` must be an alist of `(identifier . data)` pairs.  `identifier` must be
-  a string of the form `$foo`.  `data` must be a sequence of sequences of data
-  or a 2D array of data.
+  `data` must be an alist of `(identifier . data)` pairs.
+
+  Each `identifier` must be a string of the form `$foo`.  Each `data` must be
+  one of the following: a sequence of sequences of data points, an alist of data
+  points, or a 2D array of data points.
 
   `commands` must be a string or a sequence of strings.
 
@@ -86,3 +97,4 @@
       (string (gnuplot-command commands))
       (sequence (map nil #'gnuplot-command commands)))))
 
+
--- a/src/iterate.lisp	Sun May 23 16:43:03 2021 -0400
+++ b/src/iterate.lisp	Sun May 23 16:51:40 2021 -0400
@@ -727,7 +727,6 @@
          (finally (return (get-output-stream-string ,sos)))))))
 
 
-
 (defmacro-clause (ORING expr &optional INTO var)
   (let ((result (or var iterate::*result-var*)))
     `(reducing ,expr :by #'or :into ,result :initial-value nil)))