9 Plot Contracts
9.1 Plot Element Contracts
is a 2D renderer
; that is, if plot
can plot value
See 2D Renderers
for functions that construct them.
Identifies values that meet the contract elem-contract, lists of such values, lists of lists, and so on.
9.2 Appearance Argument Contracts
The contract for anchor arguments and parameters.
The 'auto anchor will place labels so they are visible on the plot
area. This anchor type is useful for point-label and similar
renderers where the labeled point might be at the edge of the plot area and
the user does not wish to calculate the exact anchor for the label.
The 'auto anchor will choose one of the 'bottom-left,
'bottom-right, 'top-left or 'top-right placements,
in that order, and will use the first one that would result in the label being
The 'auto anchor is only valid for placement of text labels, for all
other use cases, the 'auto anchor is always the same as
legend-anchor/c : contract?
| = |
| (one-of/c 'outside-top-left 'outside-top 'outside-top-right|
| 'outside-left-top 'outside-left 'outside-left-bottom|
| 'outside-right-top 'outside-right 'outside-right-bottom|
| 'outside-bottom-left 'outside-bottom 'outside-bottom-right|
The contract for the plot-legend-anchor
parameter and the
parameters for the various plot procedures.
When legend-anchor is one of the symbols from anchor/c, the
legend will be placed inside the plot area.
legend-anchor/c values which start with "outside" will place the
legend outside the plot area, for 2D plots the legend will be aligned with the
plot area, while for 3D plots the legend will be relative to the overall
plot-width and plot-height.
The 'outside-global-top value will place the legend above the plot-area,
centered on the complete plot-width. For 3D plots there is no
difference between this value and 'outside-top.
The value 'no-legend, will omit the legend from the plot, the legend
will also be omitted if none of the renderers have a #:label
specified, regardless of the value used for #:legend-anchor.
The value 'auto, will place the legend in the top-left corner of the
plot area, this is not usefull for plot legends, this anchor value is used for
renderers such as point-label.
Added in version 7.9 of package plot-lib.
A contract for very flexible color arguments.
Functions that accept a color/c
almost always convert it to an RGB triplet using ->color
The contract for #:style
arguments when they refer to lines, and paramters such as line-style
For the meaning of integer pen styles, see ->pen-style
The contract for #:style
arguments when they refer to fills, and parameters such as interval-style
For the meaning of integer brush styles, see ->brush-style
known-point-symbols : (listof symbol?)
| = |
|(list 'dot 'point 'pixel|
| 'plus 'times 'asterisk|
| '5asterisk 'odot 'oplus|
| 'otimes 'oasterisk 'o5asterisk|
| 'circle 'square 'diamond|
| 'triangle 'fullcircle 'fullsquare|
| 'fulldiamond 'fulltriangle 'triangleup|
| 'triangledown 'triangleleft 'triangleright|
| 'fulltriangleup 'fulltriangledown 'fulltriangleleft|
| 'fulltriangleright 'rightarrow 'leftarrow|
| 'uparrow 'downarrow '4star|
| '5star '6star '7star|
| '8star 'full4star 'full5star|
| 'full6star 'full7star 'full8star|
| 'circle1 'circle2 'circle3|
| 'circle4 'circle5 'circle6|
| 'circle7 'circle8 'bullet|
| 'fullcircle1 'fullcircle2 'fullcircle3|
| 'fullcircle4 'fullcircle5 'fullcircle6|
| 'fullcircle7 'fullcircle8 'none)|
A list containing the symbols that are valid points
A contract for an argument that describes an image file format.
9.3 Appearance Argument List Contracts
Returns a contract that accepts either a function from in-contract to out-contract, or a plain out-contract value.
|> (require racket/contract)|
|> (maybe-function-of-real-consumer 4)|
|> (maybe-function-of-real-consumer (λ (x) x))|
Many plot functions, such as contours and isosurfaces3d, optionally take lists of appearance values (such as (listof plot-color/c)) as arguments.
A very flexible argument contract would accept functions that produce lists of appearance values.
For example, contours would accept any f with contract (-> (listof real?) (listof plot-color/c)) for its #:colors argument.
When rendering a contour plot, contours would apply f to a list of the contour z values to get the contour colors.
However, most uses do not need this flexibility.
Therefore, plot’s functions accept either a list of appearance values or a function from a list of appropriate values to a list of appearance values.
The maybe-function/c function constructs contracts for such arguments.
In plot functions, if in-contract is a listof contract, the output list’s length need not be the same as the input list’s length.
If it is shorter, the appearance values will cycle; if longer, the tail will not be used.
If f is a function, applies f to args; otherwise returns f.
This is used inside many renderer-producing plot functions to convert maybe-function/c values to lists of appearance values.
This is equivalent to sending (λ _ '(1 2))
The next example is more sophisticated: it sends a function
-valued (plot-colors/c ivl?)
The function constructs colors from the values of the contour intervals.