plot/line
src/plot/line.tur
defstruct
LinesR
(defstruct LinesR :copy [points : (Vec Point) style : LineStyle label : cstr])
a polyline through its points, in order.
defstruct
FunctionR
(defstruct FunctionR :copy [f : (fn [float])
y = f(x), sampled over [x-min, x-max].
defstruct
ParametricR
(defstruct ParametricR :copy [f : (fn [float])
the point f(t), sampled over [t-min, t-max].
defstruct
PolarR
(defstruct PolarR :copy [f : (fn [float])
radius = f(theta), sampled over [theta-min, theta-max].
defstruct
InverseR
(defstruct InverseR :copy [f : (fn [float])
x = f(y), sampled over [y-min, y-max].
defstruct
DensityR
(defstruct DensityR :copy [values : (Vec float) bandwidth : float samples : int style : LineStyle label : cstr])
a Gaussian kernel density estimate of its sample values; a
defn
function
(function [^fat f : (fn [float])
sample y=f(x) over [x-min, x-max].
Parameters
| f | the curve, a (fn [float] float): a defn or a fn literal | |
| x-min | start of the sampled domain | |
| x-max | end of the sampled domain | |
| samples | uniform baseline sample count | |
| style | the LineStyle to stroke with | |
| label | legend text ("" for none) |
Returns
A FunctionR boxed as an AnyRenderer.
Example
(function (fn [x : float] : float (* x x)) -2.0 2.0 96 (default-line-style) "x^2")
defn
lines
(lines [vs : (Vec Point) style : LineStyle label : cstr] :)
draw a polyline through `vs`, in order.
Parameters
| vs | the points | |
| style | the LineStyle to stroke with | |
| label | legend text ("" for none) |
Returns
A LinesR boxed as an AnyRenderer.
Example
(lines (vec-of (Point 0.0 0.0) (Point 1.0 2.0)) (default-line-style) "data")
defn
parametric
(parametric [^fat f : (fn [float])
sample the Point f(t).
Parameters
| f | the curve, a (fn [float] Point) | |
| t-min | start of the parameter range | |
| t-max | end of the parameter range | |
| samples | uniform baseline sample count | |
| style | the LineStyle to stroke with | |
| label | legend text ("" for none) |
Returns
A ParametricR boxed as an AnyRenderer.
Example
(parametric (fn [t : float] : Point (Point (cos t) (sin t))) 0.0 6.283 128
(default-line-style) "circle")
defn
polar
(polar [^fat f : (fn [float])
sample radius=f(theta).
Parameters
| f | the radius, a (fn [float] float) of theta | |
| theta-min | start of the angle range, in radians | |
| theta-max | end of the angle range, in radians | |
| samples | uniform baseline sample count | |
| style | the LineStyle to stroke with | |
| label | legend text ("" for none) |
Returns
A PolarR boxed as an AnyRenderer.
Example
(polar (fn [t : float] : float 1.0) 0.0 6.283 96 (default-line-style) "r=1")
defn
inverse
(inverse [^fat f : (fn [float])
sample x=f(y) over [y-min, y-max].
Parameters
| f | the curve, a (fn [float] float) of y | |
| y-min | start of the sampled range | |
| y-max | end of the sampled range | |
| samples | uniform baseline sample count | |
| style | the LineStyle to stroke with | |
| label | legend text ("" for none) |
Returns
An InverseR boxed as an AnyRenderer.
Example
(inverse (fn [y : float] : float (* y y)) -1.0 1.0 96 (default-line-style) "x=y^2")
defn
density
(density [vs : (Vec float) bandwidth : float samples : int style : LineStyle label : cstr] :)
kernel density estimate of a sample.
Parameters
| vs | the sample values | |
| bandwidth | kernel bandwidth; 0.0 picks Silverman's rule | |
| samples | number of points the estimate is drawn through | |
| style | the LineStyle to stroke with | |
| label | legend text ("" for none) |
Returns
A DensityR boxed as an AnyRenderer.
Example
(density (vec-of 0.5 1.25 1.5 2.75) 0.0 128 (default-line-style) "kde")
Internal definitions
__draw-lines-- stroke a polyline through lowered points, breaking at NaN.__draw-function-- stroke y = f(x) through the adaptive sampler.__draw-parametric-- stroke the Point f(t) through the adaptive sampler.__draw-polar-- stroke radius = f(theta) through the adaptive sampler.__draw-inverse-- stroke x = f(y) through the adaptive sampler.__draw-density-- stroke a Gaussian KDE of `values` across the x extent.Renderer[LinesR]Renderer[FunctionR]Renderer[ParametricR]Renderer[PolarR]Renderer[InverseR]Renderer[DensityR]