10 The plot library
This library provides a basic wrapper around the line plots provided by Racket’s Plot library.
procedure
plot(title: str?, data: PlotSpec, [x: AxisSpec, y: AxisSpec]): AnyC
The main function in this library: draws a line plot from the given data, and displays it. Run inside DrRacket for best results.
The format of each argument is documented along with their contracts, below. The last two arguments describing axes are both optional.
At its simplest, a plot consisting of a single line can be drawn as follows, with a vector of 2-dimensional points forming the line as the second argument:
plot("line", [[1,1], [2,2], [3,3]])
Axes may optionally be labeled:
plot("line", [[1,1], [2,2], [3,3]], "abscissas", "ordinates")
More complex plots with multiple lines must label each line—
plot("lines, plural", [["flat", [[1,2], [2,2], [3,2]]], ["steep", [[1,0], [2,10], [3,20]]]])
constant
PlotSpec: contract?
A LineSpec, for a graph with a single (unlabeled) line.
A non-empty vector whose elements are 2-element vectors, the first of which is the name of a line, and the second is a LineSpec for each line in the graph.
[[1,1], [2,2], [3,3]]
[["flat", [[1,2], [2,2], [3,2]]], ["steep", [[1,0], [2,10], [3,20]]]]
constant
LineSpec: contract?
A LineSpec is a non-empty vector of PointSpec, and describes the points in a single line within a line plot.
constant
PointSpec: contract?
A PointSpec is a vector of two num?, which correspond to the x and y coordinate of a point, respectively.
constant
AxisSpec: contract?
An AxisSpec is a description of an axis—
A str?, which is the label for the axis.
A 2-element vector of a str? and a TransformSpec, for labels which have both a label and a transformation applied.
constant
TransformSpec: contract?
Describing an axis with a TransformSpec applies a transformation to the axis. The TransformSpecs currently supported are:
"id", the identity transformation (i.e., no transformation).
"log", which displays the axis in log-scale.