Module: plot-extend.ss
plot-extend.ss allows you to create your own constructors, further customize the appearance of the plot windows, and in general extend the package.
3.1 2d-view%
Provides an interface to drawing 2dplots. Some methods call low-level functions while others are emulated in scheme.
set-labels : string string string ->void
Sets x, y and title labelsplot-vector : vector vector ->void
Plots a single vector. First argument is the head, second is the tail.plot-vectors : (listof (listvector vector)) ->void
Plots a list of vectors. Each vector is a list of two schemevectors.plot-points : (listof vector) number ->void
Plots points using a specified character. ** provide character map **plot-line : (listof (vector number number)) ->void
Plots a line given a set of points. Each point is represented by avector.plot-contours : (listof (lisftof number)) (listof number) (listof number) (listof number) ->void
Plots a grid representing a 3d function using contours to distinguish levels. Args are grid, xvalues yvalues and levels to plot.plot-shades : (listof (lisftof number)) (listof number) (listof number) (listof number) ->void
Plots a grid representing a 3d function using shades to represent height (z).
3.2 3d-view%
Provides an interface to drawing 3d plots.
plot-surface : (listof (lisftof number)) (listof number) (listof number) ->void
Plots a grid representing a 3d function in a 3D box, showing only the top of the surface.plot-line : (listof number) (listof number) (listof number) ->void
Plots a line in 3d space. The arguments are lists of x,y and z coordinates respectively.get-z-min : -> number
Returns the minimum plottable Z coordinate.get-z-max : -> number
Returns the maximum plottable Z coordinate.get-alt : -> number
Returns the altitude (in degrees) from which the 3d box is viewed.get-az : -> number
Returns the azimuthal angle.
3.3 define-plot-type
Macro used to create new constructors. It is easiest to explain with an example, so here is an implementation of a simple line constructor:
(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 first keyword after then name of the new plot type, is used to refer to the data that will be rendered. In this case, we will are calling our data
func. For example, in the execution of(plot (line (lambda (x) x))) funcwould refer to the identity function.2dplotviewrefers to the name of the view object that the Plot-item will be applied to byplotThe
x-minandx-maxare fields in the2d-view\%object. They will be bound to the values of those fields before the execution of the body, assuming the object has the methodsget-x-minandget-x-max. This entire expression can be omitted if none of the fields are necessary (such as for plotting discrete data points).The last set of parenthesized expressions sets keywords based arguments and their default values for the constructor. To over-ride values the user needs to provide an associative list with the desired values. Ex:
(line (lambda (x) x) '((color blue)))