Plot functions from text

Trig & Exponential CurvesFunctionSineCosineExponential decay-1-0.8-0.6-0.4-0.200.20.40.60.81012345678910xf(x)
Trig & Exponential CurvesFunctionSineCosineExponential decay-1-0.8-0.6-0.4-0.200.20.40.60.81012345678910xf(x)
function Trig & Exponential Curves
x-label x
y-label f(x)
x 0 to 10

Sine blue: sin(x)
Cosine green: cos(x)
Exponential decay red: exp(-x/4)

Overview

Plots mathematical expressions as continuous curves over a range of x — you supply the formula, not a table of readings, and the curve is sampled and drawn for you. Reach for it to plot an equation, compare several curves over the same range, or model how one variable responds to another. If you already have measured numbers rather than a formula, this is the wrong chart.

When to use

  • function — you have a formula (sin(x), x^2, exp(-x/4)) and want the curve drawn from it over a continuous range.
  • line — you have a list of readings (a value per month, per day, per trial) rather than an equation.
  • scatter — you have discrete observed points, each an independent thing measured two ways, with no continuous equation behind them.

Syntax

function Chart Title
x-label X Axis Label
y-label Y Axis Label
x: min to max

Label color: expression

Metadata Keys

KeyDescriptionRequired
chartMust be functionYes
x-labelLabel for the X axisNo
y-labelLabel for the Y axisNo
xX range in format min to maxNo

The title is the rest of line 1 — there is no title directive.

Data Format

Each data line defines a named function with an optional color and a math expression:

Label color: expression

Expressions support:

  • Basic arithmetic: +, -, *, /
  • Exponents: x^2, x^3
  • Functions: sin, cos, tan, exp, ln, log, sqrt, abs
  • Constants: pi, e
  • The variable x represents the X axis value

Colors

Append a color name (lowercase) after the function name:

Parabola blue: x^2
Linear red: 2*x + 1

Shading the area below a curve

Add the fill directive to shade the band between each curve and the y=0 baseline — the same directive the line chart uses. The band is a soft 25% tint by default; add fill-solid for an opaque fill. (fill-outline is ignored here — hollowing the band would erase it.)

TrajectoriesFunction15 degrees30 degrees051015202530354045020406080100120140160180200220240
TrajectoriesFunction15 degrees30 degrees051015202530354045020406080100120140160180200220240
function Trajectories
x 0 to 250
fill

15 degrees blue: -0.001*x^2 + 0.27*x
30 degrees green: -0.002*x^2 + 0.58*x

Appearance

Every chart accepts the universal appearance directives:

DirectiveEffect
fill-tintSoft tinted fills (default).
fill-solidSaturated solid fills.
fill-outlineOutline only, no fill.
no-titleHide the title line.
no-legendHide the legend.

Colors come from the active palette — see Colors. Set the palette and light/dark theme at render time with --palette <name> and --theme light|dark|transparent.

Next