Plot functions from text
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
| Key | Description | Required |
|---|---|---|
chart | Must be function | Yes |
x-label | Label for the X axis | No |
y-label | Label for the Y axis | No |
x | X range in format min to max | No |
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
xrepresents 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.)
Appearance
Every chart accepts the universal appearance directives:
| Directive | Effect |
|---|---|
fill-tint | Soft tinted fills (default). |
fill-solid | Saturated solid fills. |
fill-outline | Outline only, no fill. |
no-title | Hide the title line. |
no-legend | Hide 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
- Related:
line·scatter - Then: Colors & palettes