anchor.diff:  	     do (format stream "~1,8f ~1,8f~%" xi yi))
   	  (format stream "e~%"))
   
  -(defun plot (&rest args)
  -  ;; Let's say things are (x y title) for now
  -  (with-plot stream
  -    (if (consp (car args))
  +(defun plot (plot-sexps &key title (terminal :wxt) (pathspec "") x-label y-label)
  +  ;; Make sure args is always a list of plot specs
  +  (let ((plot-sexps (if (consp (car plot-sexps))
  +			plot-sexps
  +			(list plot-sexps))))
   
  -	;; List of things to plot
  -	(progn
  -	  (loop for plot in (car args)
  -	     do (format stream "plot '-' using 1:2 ~a" (parse-style (third plot)))
  -	     unless (eql plot (car (last (car args))))
  -	     do (format stream ","))
  -	       
  -	  (loop for plot in (car args)
  -	     do (destructuring-bind (x y nil) plot
  -		  (print-vectors-to-stream stream x y)))) ; hah! second-class functions to the rescue!
  -	
  +    (with-plot (stream terminal pathspec)
  +       (when title (format stream "set title ~S~%" title))
  +       (when x-label (format stream "set xlabel ~S~%" x-label))
  +       (when y-label (format stream "set ylabel ~S~%" y-label))
   
  -	;; One thing to plot, yay!
  -	(let ((x (first args))
  -	      (y (second args))
  -	      (style (parse-style (third args))))
  -	  (format stream "plot '-' using 1:2 ~a~%" style)
  -	  (print-vectors-to-stream stream x y)))))
  +      ;; Write line styles to stream
  +      (loop
  +	 for plot in plot-sexps
  +	 for number from 1 by 1
  +	 do (parse-style stream number (subseq plot 2)))
   
  -(defun image (data)
  -  (with-plot s
  +      ;; Write plot commands to stream
  +      (loop
  +	 for plot in plot-sexps
  +	 for number from 1 by 1
  +	 initially (princ "plot " stream)
  +	 do (format stream
  +		    "'-' using 1:2 ls ~d title ~S with ~a"
  +		    number
  +		    (or (getf plot :title) "")
  +		    (or (case (getf plot :line-style)
  +			  (:lines "lines")
  +			  (:points "points")
  +			  (:lines-points "linespoints")
  +			  (:impulses "impulses")
  +			  (:dots "dots")
  +			  (:steps "steps")
  +			  ;; FIXME: Add others once we can parse more vectors (errorbars)
  +			  (t "lines"))))
  +	 unless (= (length plot-sexps) number)
  +	 do (princ ", " stream)
  +	 finally (princ #\Newline stream))
  +
  +      
  +      (loop
  +	 for plot in plot-sexps
  +	 do (destructuring-bind (x y) (subseq plot 0 2)
  +	      ;; hah! second-class functions to the rescue!
  +	      (print-vectors-to-stream stream x y))))))
  +
  +(defun image (data &key title (terminal :wxt) (pathspec "") x-label y-label)
  +  (with-plot (s terminal pathspec)
  +    (when title (format s "set title ~S~%" title))
  +    (when x-label (format s "set xlabel ~S~%" x-label))
  +    (when y-label (format s "set ylabel ~S~%" y-label))
  +
       (format s "set pm3d map~%")
  +    (format s "set size ratio 1~%")
       (format s "splot '-' matrix~%")
       (loop for i from (1- (array-dimension data 1)) downto 0
          do (loop for j from 0 upto (1- (array-dimension data 0))
  
positive.code: 				    :input :stream))
        *gnuplot-process*))
  
  (defun parse-style (style-alist)
    (with-output-to-string (s)
      ;; Do we have a title?  Print it first
      (when (assoc :title style-alist)
        (format s " title ~S" (cadr (assoc :title style-alist)))
        (setf style-alist (remove-if (lambda (k) (eq (car k) :title)) style-alist)))
  
      ;; More style directives?  They live together
      (when style-alist
        (format s " with ")
        (loop for (key value) in style-alist
  	 do (cond
  	      ((eq key :line-style)
  	       (format s "~a" (cond
  			      ((eq value :line) "line")
  			      ((eq value :line-points) "linespoints"))))
  	      ((eq key :yerr)
  	       (format s " yerr ")))))))
  
  (defun print-vectors-to-stream (stream x y)
  	  (loop for xi across x
  
negative.code: (defparameter *gnuplot-path* #p"/usr/bin/gnuplot")
  (defparameter *gnuplot-args* '("-persist"))
  (defparameter *gnuplot-process* nil)
  ;; Thanks http://yujianzhang.blogspot.com/2007/12/nicer-fonts-for-gnuplot.html
  (defparameter *gnuplot-font* "/usr/share/fonts/bitstream-vera/Vera.ttf,12")
  
  (defmacro with-plot ((stream &optional terminal pathspec) &body body)
    (when (and (member terminal '(:eps :ps :png :jpg))
  	     (not pathspec))
      (error "Attempting to plot to a file with no pathspec given"))
    `(let ((gnuplot (ensure-gnuplot-connection)))
       (with-open-stream (,stream (external-program:process-input-stream gnuplot))
  					;with-open-file (,stream #p"./test" :direction :output :if-exists :supersede)
         (format ,stream "set term ~a font ~S~%" (string-downcase ,terminal) *gnuplot-font*)
         (when ,pathspec (format ,stream "set output ~S~%" (namestring ,pathspec)))
         ,@body)))
  
  (defun close-gnuplot-connection ()
    (when *gnuplot-process*
  