diff --git a/collects/plot/plot.scrbl b/collects/plot/plot.scrbl index 3af0ea7439..beea6f878a 100644 --- a/collects/plot/plot.scrbl +++ b/collects/plot/plot.scrbl @@ -313,13 +313,23 @@ A 3-D @scheme[data] value is represented as a procedure that takes a @defproc[(points [vecs (listof (vector/c real? real?))] - [#:sym sym (one-of/c 'square 'circle 'odot 'bullet) 'square] + [#:sym sym (or/c character? integer? symbol?) 'fullsquare] [#:color color plot-color? 'black]) ((is-a?/c 2d-view%) . -> . void?)]{ Creates 2-D plot data (to be provided to @scheme[plot]) given a list of points specifying locations. The @scheme[sym] argument determines -the appearance of the points.} +the appearance of the points. It can be a symbol, an ASCII character, +or a small integer (between -1 and 127). The following symbols are +known: @scheme['pixel], @scheme['dot], @scheme['plus], +@scheme['asterisk], @scheme['circle], @scheme['times], +@scheme['square], @scheme['triangle], @scheme['oplus], @scheme['odot], +@scheme['diamond], @scheme['5star], @scheme['6star], +@scheme['fullsquare], @scheme['bullet], @scheme['full5star], +@scheme['circle1], @scheme['circle2], @scheme['circle3], +@scheme['circle4], @scheme['circle5], @scheme['circle6], +@scheme['circle7], @scheme['circle8], @scheme['leftarrow], +@scheme['rightarrow], @scheme['uparrow], @scheme['downarrow]. } @@ -588,34 +598,35 @@ Sets the axis labels and title.} @defmethod[(plot-vector [head (vector/c real? real?)] [tail (vector/c real? real?)]) void?]{ - + Plots a single vector.} - + @defmethod[(plot-vectors [vecs (listof (list/c (vector/c real? real?) (vector/c real? real?)))]) void?]{ - + Plots a set of vectors.} @defmethod[(plot-points [points (listof (vector/c real? real?))] - [sym (one-of/c 'square 'circle 'odot 'bullet)]) + [sym (or/c character? integer? symbol?)]) void?]{ - -Plots points using a specified symbol.} + +Plots points using a specified symbol. See @scheme[points] for +possible values for @scheme[sym]} @defmethod[(plot-line [points (listof (vector/c real? real?))]) void?]{ Plots a line given a set of points.} - + @defmethod[(plot-contours [grid (listof (listof real?))] [xs (listof real?)] [ys (listof real?)] [levels (listof real?)]) void?]{ - + Plots a grid representing a 3-D function using contours to distinguish levels.} @defmethod[(plot-shades [grid (listof (listof real?))] diff --git a/collects/plot/renderers.ss b/collects/plot/renderers.ss index f5b8c51942..eb5ea83df8 100644 --- a/collects/plot/renderers.ss +++ b/collects/plot/renderers.ss @@ -86,7 +86,7 @@ (plot-contours grid x-vals y-vals c-levels)))) ; shade : (number number -> number) [number] [symbol] [number] [number / listof-number] -> (2dplotview -> nothing) - ; renders a shade plot given function and shade levels + ; renders a shade plot given function and shade levels (define-plot-type shade fun3d 2dplotview (x-min x-max y-min y-max) ((samples 50) (levels 10)) @@ -96,39 +96,73 @@ (z-max (apply max (map (lambda (row) (apply max row)) grid))) (z-min (apply min (map (lambda (row) (apply min row)) grid))) (c-levels (x-values levels z-min z-max))) - (send* 2dplotview + (send* 2dplotview (plot-shades grid x-vals y-vals c-levels)))) - + ; points : (listof vector) [symbol] -> (2dplotview -> nothing) ; plots a set of points using a specific character (define-plot-type points - lop 2dplotview ((sym 'square) (color 'black)) - (send* 2dplotview + lop 2dplotview ((sym 'fullsquare) (color 'black)) + (send* 2dplotview (set-line-color color) - (plot-points lop - (cond [(assq sym point-syms) => cadr] - [else (error "Symbol not found in table!")])))) - + (plot-points lop + (cond [(and (integer? sym) (<= -1 sym 127)) sym] + [(and (char? sym) + (char<= (integer->char 32) + sym + (integer->char 127))) + (char->integer sym)] + [(assq sym point-syms) => cadr] + [else (error "Symbol not found in table!")])))) + ; the symbol-> char table (define point-syms - '((square 16) (odot 9) (bullet 17) (circle 4))) + '((pixel -1) + (dot 1) + (plus 2) + (asterisk 3) + (circle 4) + (times 5) + (square 6) + (triangle 7) + (oplus 8) + (odot 9) + ;; (??? 10) + (diamond 11) + (5star 12) + ;; (square 13) + ;; (??? 14) + (6star 15) + (fullsquare 16) + (bullet 17) + (full5star 18) + ;; (square 19) + (circle1 20) + (circle2 21) + (circle3 22) + (circle4 23) + (circle5 24) + (circle6 25) + (circle7 26) + (circle8 27) + (leftarrow 28) + (rightarrow 29) + (uparrow 30) + (downarrow 31))) - - - ;; 3D PLOTTERS ; plot a surface - (define-plot-type surface + (define-plot-type surface fun3d 3dplotview (x-min x-max y-min y-max) ((samples 50) (color 'black) (width '1)) (let* ((x-vals (x-values samples x-min x-max)) (y-vals (x-values samples y-min y-max)) (grid (zgrid fun3d x-vals y-vals samples))) - (send* 3dplotview + (send* 3dplotview (set-line-color color) (set-line-width width) (plot-surface x-vals y-vals grid)))) - + (define-plot-type mesh3d fun3d 3dplotview (x-min x-max y-min y-max z-min z-max) ((samples 50) (width '1) (levels 10) (color #t) (lines #t)