anchor.diff:          (let ((bz 30)
                 (bg (append (mapcar #'(lambda (x) (- 1.0 x)) background) '(0.8))))
             (destructuring-bind (xb yb w h) (max-extents legend)
  -            (apply #'set-source-rgba bg)
  -            (rectangle (+ bz bx -5 xb) (+ yb by bz -5) (+ w 75) (+ 10 (* h (length legend))))
  -            (fill-path)
  -            (loop for txt in legend
  -               for c in colors
  -               as y = (+ bz by) then (+ y h) do
  -                 (apply #'set-source-rgb background)
  -                 (move-to (+ bx bz) y)
  -                 (show-text txt)
  -                 (move-to (+ bx bz 5 w xb) (+ (/ yb 2) y))
  -                 (apply #'set-source-rgb c)
  -                 (line-to (+ bx bz 65 w xb) (+ (/ yb 2) y))
  -                 (stroke))))))
  +            (let ((h (+ 5 h)))
  +              (apply #'set-source-rgba bg)
  +              (rectangle (+ bz bx -5 xb) (+ yb by bz -5) (+ w 75) (+ 10 (* h (length legend))))
  +              (fill-path)
  +              (loop for txt in legend
  +                 for c in colors
  +                 as y = (+ bz by) then (+ y h) do
  +                   (apply #'set-source-rgb background)
  +                   (move-to (+ bx bz) y)
  +                   (show-text txt)
  +                   (move-to (+ bx bz 5 w xb) (+ (/ yb 2) y))
  +                   (apply #'set-source-rgb c)
  +                   (line-to (+ bx bz 65 w xb) (+ (/ yb 2) y))
  +                   (stroke)))))))
                   
       (destroy *context*)))
   
  
positive.code:   (:use :common-lisp
          :cairo)
    (:export :plot
             :plot-xy))
  
  (in-package :plot2d)
  
  
negative.code:          (yvals (loop for yv in vals
                     collect (loop for y in yv collect (second y)))))
      (plot-xy xvals yvals :aspect aspect :background background :palette palette :legend legend :labels labels :width width :filename filename :format format)))
  
  
  (defun plot/polar+a (func &key (theta-range (list 0 (+ pi pi))) (a-values '(1.0)) (aspect 1.0) (samples 200) (background (list 0.2 0.2 0.2)) (palette '((1.0 0.2 0.2) (0.2 1.0 0.2) (0.2 0.2 1.0)))
                       (legend nil) (labels nil) (width 800) (filename "plot2d.pdf") (format :pdf))
    "Plot a polar-coordinate function parameterized by a. `FUNC` takes two arguments, theta and a."
    (flet ((func/ar (a f)
             (let* ((theta (loop for x from (first theta-range) to (second theta-range) by (/ (- (second theta-range) (first theta-range)) samples) collect x))
                    (r (loop for n in theta collecting (funcall f n a))))
               (list
                (loop
                   for th in theta
                   for rv in r
                   collect (* rv (cos th)))
                (loop
                   for th in theta
                   for rv in r
                   collect (* rv (sin th)))))))
      (destructuring-bind (p q) (loop for a in a-values
                                   as (x y) = (func/ar a func)
                                   collecting x into xv
                                   collecting y into yv
                                   finally (return (list xv yv)))
        (plot/xy p q 
                 :aspect aspect
                 :background background
                 :palette palette
                 :legend legend
                 :labels labels
                 :width width
                 :filename filename
                 :format format))))
  
      
    
  