On this page:
12.1 Plotting
plot
plot3d
points
line
error-bars
vector-field
contour
shade
surface
mix
plot-color?
12.2 Miscellaneous Functions
derivative
gradient
make-vec
5.3.4

12 Compatibility Module

Alexander Friedman,
Jamie Raymond,
and Neil Toronto

 (require plot/compat)

This module provides an interface compatible with PLoT 5.1.3 and earlier.

Do not use both plot and plot/compat in the same module. It is tempting to try it, to get both the new features and comprehensive backward compatibility. But to enable the new features, the objects plotted in plot have to be a different data type than the objects plotted in plot/compat. They do not coexist easily, and trying to make them do so will result in contract violations.

12.1 Plotting

procedure

(plot data    
  [#:width width    
  #:height height    
  #:x-min x-min    
  #:x-max x-max    
  #:y-min y-min    
  #:y-max y-max    
  #:x-label x-label    
  #:y-label y-label    
  #:title title    
  #:fgcolor fgcolor    
  #:bgcolor bgcolor    
  #:lncolor lncolor    
  #:out-file out-file])  (is-a?/c image-snip%)
  data : ((is-a?/c 2d-plot-area%) . -> . void?)
  width : real? = 400
  height : real? = 400
  x-min : real? = -5
  x-max : real? = 5
  y-min : real? = -5
  y-max : real? = 5
  x-label : string? = "X axis"
  y-label : string? = "Y axis"
  title : string? = ""
  fgcolor : (list/c byte? byte? byte?) = '(0 0 0)
  bgcolor : (list/c byte? byte? byte?) = '(255 255 255)
  lncolor : (list/c byte? byte? byte?) = '(255 0 0)
  out-file : (or/c path-string? output-port? #f) = #f
Plots data in 2D, where data is generated by functions like points or line.

A data value is represented as a procedure that takes a 2d-plot-area% instance and adds plot information to it.

The result is a image-snip% for the plot. If an #:out-file path or port is provided, the plot is also written as a PNG image to the given path or port.

The #:lncolor keyword argument is accepted for backward compatibility, but does nothing.

procedure

(plot3d data    
  [#:width width    
  #:height height    
  #:x-min x-min    
  #:x-max x-max    
  #:y-min y-min    
  #:y-max y-max    
  #:z-min z-min    
  #:z-max z-max    
  #:alt alt    
  #:az az    
  #:x-label x-label    
  #:y-label y-label    
  #:z-label z-label    
  #:title title    
  #:fgcolor fgcolor    
  #:bgcolor bgcolor    
  #:lncolor lncolor    
  #:out-file out-file])  (is-a?/c image-snip%)
  data : ((is-a?/c 3d-plot-area%) . -> . void?)
  width : real? = 400
  height : real? = 400
  x-min : real? = -5
  x-max : real? = 5
  y-min : real? = -5
  y-max : real? = 5
  z-min : real? = -5
  z-max : real? = 5
  alt : real? = 30
  az : real? = 45
  x-label : string? = "X axis"
  y-label : string? = "Y axis"
  z-label : string? = "Z axis"
  title : string? = ""
  fgcolor : (list/c byte? byte? byte?) = '(0 0 0)
  bgcolor : (list/c byte? byte? byte?) = '(255 255 255)
  lncolor : (list/c byte? byte? byte?) = '(255 0 0)
  out-file : (or/c path-string? output-port? #f) = #f
Plots data in 3D, where data is generated by a function like surface. The arguments alt and az set the viewing altitude (in degrees) and the azimuth (also in degrees), respectively.

A 3D data value is represented as a procedure that takes a 3d-plot-area% instance and adds plot information to it.

The #:lncolor keyword argument is accepted for backward compatibility, but does nothing.

procedure

(points vecs [#:sym sym #:color color])

  ((is-a?/c 2d-plot-area%) . -> . void?)
  vecs : (listof (vectorof real?))
  sym : (or/c char? string? exact-integer? symbol?) = 'square
  color : plot-color? = 'black
Creates 2D plot data (to be provided to plot) given a list of points specifying locations. The sym argument determines 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: 'pixel, 'dot, 'plus, 'asterisk, 'circle, 'times, 'square, 'triangle, 'oplus, 'odot, 'diamond, '5star, '6star, 'fullsquare, 'bullet, 'full5star, 'circle1, 'circle2, 'circle3, 'circle4, 'circle5, 'circle6, 'circle7, 'circle8, 'leftarrow, 'rightarrow, 'uparrow, 'downarrow.

procedure

(line f 
  [#:samples samples 
  #:width width 
  #:color color 
  #:mode mode 
  #:mapping mapping 
  #:t-min t-min 
  #:t-max t-max]) 
  ((is-a?/c 2d-plot-area%) . -> . void?)
  f : (real? . -> . (or/c real? (vector/c real? real?)))
  samples : (and/c exact-integer? (>=/c 2)) = 150
  width : (>=/c 0) = 1
  color : plot-color/c = 'red
  mode : (one-of/c 'standard 'parametric) = 'standard
  mapping : (one-of/c 'cartesian 'polar) = 'cartesian
  t-min : real? = -5
  t-max : real? = 5
Creates 2D plot data to draw a line.

The line is specified in either functional, i.e. y = f(x), or parametric, i.e. x,y = f(t), mode. If the function is parametric, the mode argument must be set to 'parametric. The t-min and t-max arguments set the parameter when in parametric mode.

procedure

(error-bars vecs [#:color color])

  ((is-a?/c 2d-plot-area%) . -> . void?)
  vecs : (listof (vector/c real? real? real?))
  color : plot-color? = 'black
Creates 2D plot data for error bars given a list of vectors. Each vector specifies the center of the error bar (x,y) as the first two elements and its magnitude as the third.

procedure

(vector-field f 
  [#:samples samples 
  #:width width 
  #:color color 
  #:style style]) 
  ((is-a?/c 2d-plot-area%) . -> . void?)
  f : ((vector/c real? real?) . -> . (vector/c real? real?))
  samples : (and/c exact-integer? (>=/c 2)) = 20
  width : exact-positive-integer? = 1
  color : plot-color? = 'red
  style : (one-of/c 'scaled 'normalized 'real) = 'scaled
Creates 2D plot data to draw a vector-field from a vector-valued function.

procedure

(contour f 
  [#:samples samples 
  #:width width 
  #:color color 
  #:levels levels]) 
  ((is-a?/c 2d-plot-area%) . -> . void?)
  f : (real? real? . -> . real?)
  samples : exact-nonnegative-integer? = 50
  width : (>=/c 0) = 1
  color : plot-color/c = 'black
  levels : (or/c (and/c exact-integer? (>=/c 2)) (listof real?))
   = 10
Creates 2D plot data to draw contour lines, rendering a 3D function a 2D graph cotours (respectively) to represent the value of the function at that position.

procedure

(shade f [#:samples samples #:levels levels])

  ((is-a?/c 2d-plot-area%) . -> . void?)
  f : (real? real? . -> . real?)
  samples : (and/c exact-integer? (>=/c 2)) = 50
  levels : (or/c (and/c exact-integer? (>=/c 2)) (listof real?))
   = 10
Creates 2D plot data to draw like contour, except using shading instead of contour lines.

procedure

(surface f 
  [#:samples samples 
  #:width width 
  #:color color]) 
  ((is-a?/c 3d-plot-area%) . -> . void?)
  f : (real? real? . -> . real?)
  samples : (and/c exact-integer? (>=/c 2)) = 50
  width : (>=/c 0) = 1
  color : plot-color/c = 'black
Creates 3D plot data to draw a 3D surface in a 2D box, showing only the top of the surface.

procedure

(mix data ...)  (any/c . -> . void?)

  data : (any/c . -> . void?)
Creates a procedure that calls each data on its argument in order. Thus, this function can composes multiple plot datas into a single data.

procedure

(plot-color? v)  boolean?

  v : any/c
Returns #t if v is one of the following symbols, #f otherwise:

'white 'black 'yellow 'green 'aqua 'pink
'wheat 'grey 'blown 'blue 'violet 'cyan
'turquoise 'magenta 'salmon 'red

12.2 Miscellaneous Functions

procedure

(derivative f [h])  (real? . -> . real?)

  f : (real? . -> . real?)
  h : real? = 1e-06
Creates a function that evaluates the numeric derivative of f. The given h is the divisor used in the calculation.

procedure

(gradient f [h])

  ((vector/c real? real?) . -> . (vector/c real? real?))
  f : (real? real? . -> . real?)
  h : real? = 1e-06
Creates a vector-valued function that computes the numeric gradient of f.

procedure

(make-vec fx fy)

  ((vector/c real? real?) . -> . (vector/c real? real?))
  fx : (real? real? . -> . real?)
  fy : (real? real? . -> . real?)
Creates a vector-valued function from two parts.