Version: 5.2.1
8 Plot Utilities
8.1 Formatting
Given a range, returns the number of decimal places necessary to distinguish numbers in the range.
This may return negative numbers for large ranges.
Converts a real number to a plot label.
Used to format axis tick labels,
point-labels, and numbers in legend entries.
Converts an interval to a plot label.
If
i =
(ivl x-min x-max), the number of digits used is
(digits-for-range x-min x-max 10 extra-digits) when both endpoints are
rational?.
Otherwise, it is unspecified—
but will probably remain
15.
Converts an integer into a string of superscript Unicode characters.
Systems running some out-of-date versions of Windows XP have difficulty with Unicode superscripts for 4 and up.
Because
integer->superscript is used by every number formatting function to format exponents, if you have such a system, PLoT will apparently not format all numbers with exponents correctly (until you update it).
8.2 Sampling
Returns a list of uniformly spaced real numbers between start and end.
If start? is #t, the list includes start.
If end? is #t, the list includes end.
This function is used internally to generate sample points.
Like
linear-seq, but accepts a list of reals instead of a start and end.
The
#:start? and
#:end? keyword arguments work as in
linear-seq.
This function does not guarantee that each inner value will be in the returned list.
Generates a list of reals that, if transformed using transform, would be uniformly spaced.
This is used to generate samples for transformed axes.
Represents a function that maps over lists differently than
(map f xs).
With some functions, mapping over a list can be done much more quickly if done specially.
(An example is a piecewise function with many pieces that first must decide which interval its input belongs to. Deciding that for many inputs can be done more efficiently by sorting all the inputs first.)
Renderer-producing functions that accept a (-> real? real?) also accept a mapped-function, and use its fmap to sample more efficiently.
Given samples and a kernel bandwidth, returns a
mapped-function representing a kernel density estimate, and bounds, outside of which the density estimate is zero.
Used by
density.
8.3 Plot Colors and Styles
Interpolates between colors—
red, green and blue components separately—
using
linear-seq.
The
#:start? and
#:end? keyword arguments work as in
linear-seq.
Interpolates between colors—
red, green and blue components separately—
using
linear-seq*.
The
#:start? and
#:end? keyword arguments work as in
linear-seq.
Converts a non-integer plot color to an RGB triplet.
Symbols are converted to strings, and strings are looked up in a color-database<%>.
Lists are unchanged, and color% objects are converted straightforwardly.
This function does not convert integers to RGB triplets, because there is no way for it to know whether the color will be used for a pen or for a brush.
Use ->pen-color and ->brush-color to convert integers.
Converts a
line color to an RGB triplet. This function interprets integer colors as darker and more saturated than
->brush-color does.
Non-integer colors are converted using ->color.
Integer colors are chosen for good pairwise contrast, especially between neighbors.
Integer colors repeat starting with 128.
Converts a
fill color to an RGB triplet. This function interprets integer colors as lighter and less saturated than
->pen-color does.
Non-integer colors are converted using ->color.
Integer colors are chosen for good pairwise contrast, especially between neighbors.
Integer colors repeat starting with 128.
In the above example, mapping ->brush-color over the list is actually unnecessary, because contour-intervals uses ->brush-color internally to convert fill colors.
The
function-interval function generally plots areas using a fill color and lines using a line color.
Both kinds of color have the default value
3.
The following example reverses the default behavior; i.e it draws areas using
line color
3 and lines using
fill color
3:
Converts a symbolic pen style or a number to a symbolic pen style.
Symbols are unchanged.
Integer pen styles repeat starting at 5.
Converts a symbolic brush style or a number to a symbolic brush style.
Symbols are unchanged.
Integer brush styles repeat starting at 7.
8.4 Plot-Specific Math
8.4.1 Real Functions
Converts degrees to radians.
Converts radians to degrees.
Converts 2D polar coordinates to 3D cartesian coordinates.
Converts 3D polar coordinates to 3D cartesian coordinates.
See
parametric3d for an example of use.
Returns #t if x is either +inf.0 or -inf.0.
Returns #t if x is +nan.0.
Various number-formatting functions use this.
Various number-formatting functions use this.
Returns
#f if
x is
#f; otherwise
(inexact->exact x).
Use this to convert interval endpoints, which may be
#f, to exact numbers.
8.4.2 Vector Functions
Vector arithmetic. Equivalent to
vector-mapp-ing arithmetic operators over vectors, but specialized so that 2- and 3-vector operations are much faster.
Examples: |
> (v+ #(1 2) #(3 4)) | '#(4 6) | > (v- #(1 2) #(3 4)) | '#(-2 -2) | > (vneg #(1 2)) | '#(-1 -2) | > (v* #(1 2 3) 2) | '#(2 4 6) | > (v/ #(1 2 3) 2) | '#(1/2 1 3/2) |
|
Like
equal? specialized to numeric vectors, but compares elements using
=.
Examples: |
> (equal? #(1 2) #(1 2)) | #t | > (equal? #(1 2) #(1.0 2.0)) | #f | > (v= #(1 2) #(1.0 2.0)) | #t |
|
Returns the right-hand vector cross product of v1 and v2.
Examples: |
> (vcross #(1 0 0) #(0 1 0)) | '#(0 0 1) | > (vcross #(0 1 0) #(1 0 0)) | '#(0 0 -1) | > (vcross #(0 0 1) #(0 0 1)) | '#(0 0 0) |
|
Returns the dot product of v1 and v2.
Returns the squared magnitude of
v. Equivalent to
(vdot v v).
Returns the magnitude of
v. Equivalent to
(sqrt (vmag^2 v)).
Returns a normal vector in the same direction as v. If v is a zero vector, returns v.
Examples: |
> (vnormalize #(1 1 0)) | '#(0.7071067811865475 0.7071067811865475 0) | > (vnormalize #(1 1 1)) | '#(0.5773502691896258 0.5773502691896258 0.5773502691896258) | > (vnormalize #(0 0 0.0)) | '#(0 0 0.0) |
|
Returns the center of the smallest bounding box that contains vs.
Example: |
> (vcenter '(#(1 1) #(2 2))) | '#(3/2 3/2) |
|
Returns
#t if every element of
v is
rational?.
8.4.3 Intervals and Interval Functions
Represents a closed interval.
An interval with two real-valued endpoints always contains the endpoints in order:
> (ivl 0 1) |
(ivl 0 1) |
> (ivl 1 0) |
(ivl 0 1) |
An interval can have infinite endpoints:
> (ivl -inf.0 0) |
(ivl -inf.0 0) |
> (ivl 0 +inf.0) |
(ivl 0 +inf.0) |
> (ivl -inf.0 +inf.0) |
(ivl -inf.0 +inf.0) |
Functions that return rectangle renderers, such as rectangles and discrete-histogram3d, accept vectors of ivls as arguments.
The ivl struct type is also provided by plot so users of such renderers do not have to require plot/utils.
Returns
#t if
i is an interval and each of its endpoints is
rational?.
Given a list of points, returns intervals between each pair.
8.5 Dates and Times
Converts various date/time representations into UTC seconds, respecting time zone offsets.
For dates, the value returned is the number of seconds since a system-dependent UTC epoch.
See date-ticks for more information.
To plot a time series using dates pulled from an SQL database, simply set the relevant axis ticks (probably plot-x-ticks) to date-ticks, and convert the dates to seconds using datetime->real before passing them to lines.
To keep time zone offsets from influencing the plot, set them to 0 first.
Does sql-time? work?
db/base
A time representation that accounts for days, negative times (using negative days), and fractional seconds.
PLoT (specifically time-ticks) uses plot-time internally to format times, but because renderer-producing functions require only real values,
user code should not need it. It is provided just in case.
Convert
plot-times to real seconds, and vice-versa.