statFunction

Create Aes based on a function

statFunction
(
FUNC
T
)
(
FUNC func
,
T min
,
T max
,
size_t precision = 50
)
if (
isCallable!FUNC
)

Parameters

func FUNC

Function

min T

x coordinate to start from

max T

x coordinate to end at

precision size_t

Number of points to calculate

Examples

/// http://blackedder.github.io/ggplotd/images/function.png
import std.random : uniform;
import std.typecons : Tuple; import ggplotd.stat : statFunction; 
import ggplotd.ggplotd : GGPlotD; 
import ggplotd.geom : geomLine, geomPoint;
import ggplotd.range : mergeRange;

auto f = (double x) { return x / (1 + x); };

auto aes = statFunction(f, 0.0, 10);
auto gg = GGPlotD().put(geomLine(aes));

// Generate some noisy points 
auto f2 = (double x) { return x / (1 + x) * uniform(0.75, 1.25); };
auto aes2 = f2.statFunction(0.0, 10, 25);

// Show points in different colour
auto withColour = Tuple!(string, "colour")("aquamarine").mergeRange(aes2);
gg = gg.put(withColour.geomPoint);

gg.save("function.png");

Meta