[plt-scheme] PLoT improvements: documentation and writing text into a plot

From: Danny Yoo (dyoo at hkn.eecs.berkeley.edu)
Date: Wed Jan 24 19:18:24 EST 2007

Hi everyone,

Can the following be added to the documentation on PLoT?  In the example 
for define-plot-type (Section 3.3), there's a bit of implied knowledge:

(define-plot-type line
    func 2dplotview (x-min x-max) ((samples 150) (color 'red) (width 1))
    (send* 2dplotview
      (set-line-color color) (set-line-width width)
      (plot-line (map (lambda (x) (vector x (func x)))
                      (x-values samples x-min x-max)))))

The definition of X-VALUES and Y-VALUES is undocumented, so the example 
isn't self-contained; there should be some note in the documentation to 
either refer to:

     (lib "math.ss" "plot")

where those functions are defined, or at least to document their purpose 
in the PLoT manual.  As it is, those functions seemed magical.

More importantly, it's also not clear how to write arbitrary text labels 
to the plot; to my surprise, this behavior isn't nicely exposed as a 

After reading:


I cooked up the following:

(module plot-label mzscheme
   (require (lib "plot.ss" "plot")
            (lib "math.ss" "plot")
            (lib "class.ss")
            (lib "plplot.ss" "plot")
            (lib "plot-extend.ss" "plot"))

   ;; low level helper function
   ;; todo: support dx, dx, justification parameters
   (define (plot-text x y text)
     (pl-write-text x y 0 0 0 text))

   ;; plot-item for text
   ;; (text (listof (vector number number string)) [color 'black])
   (define-plot-type text lop
     2dplotview ((color 'black))
       (send 2dplotview set-line-color color)
       (for-each (lambda (p)
                   (plot-text (vector-x p) (vector-y p) (vector-ref p 2)))

Finally, I could triumphantly draw text into my plot:

> (plot (text (list #[0 0 "hello"] #[2 1 "world"]) [color 'red]))

Has anyone already done this?  If not, can something like this be added to 
the API?  It seems like critical functionality to me.  Thanks!

Posted on the users mailing list.