Skip to content
Jennifer Programming Language

plot API reference

Data plotting to SVG: turn numbers into a self-contained <svg> chart string you can write to a .svg file or drop into HTML. A unified chart renders one or more Series (line / points / both / area, solid or dashed, with optional error bars and marker shapes) with a legend; line / scatter / bar / bars / histogram are focused wrappers. bars groups or stacks multiple series and supports negative (diverging) values. Charts support log scales, a date axis, fonts, configurable margins, positioned legends, reference lines, data labels, and native <title> hover tooltips. save writes the SVG to a file. Pure Jennifer over math and time / fs / strings / lists / convert; both binaries; the visual companion to the stats / ml numeric stack.

Import with import "plot.j" as plot;. See the plot guide for prose and examples.

Contents

NameWhat it is
barA single-series vertical bar chart: one bar per labelled category, from zero (negative values diverge below).
barsA multi-series bar chart: one group of bars per labelled category.
chartRender one or more Series on shared axes, with a legend for named series.
defaultsSensible defaults: a 640x400 canvas, no title / labels, blue data on white, a sans-serif 11px base font, gr...
floatsConvert a list of int to a list of float, since the chart functions take float data and an int list doe...
histogramA histogram of data into bins equal-width buckets over the data range, drawing the bucket counts as adj...
hlineA horizontal reference line at y = value (a threshold / target).
lineA line chart of a single series.
pointsA points (scatter) series (mark "points").
saveWrite an SVG chart string to a file, returning the path.
scatterA scatter plot of a single series.
seriesA line series (mark "line").
vlineA vertical reference line at x = value (a marker in time / along x).
Optionsstruct: Chart options: canvas size, captions, colours, fonts, margins, axis modes, legend placement, data labels, t...
RefLinestruct: A reference line drawn across the plot at a constant value on one axis - a threshold, target, or marker.
Seriesstruct: One plotted data series.

Functions

bar

jennifer
plot.bar(labels as list of string, values as list of float, opts as Options)

A single-series vertical bar chart: one bar per labelled category, from zero (negative values diverge below). A convenience over bars.

labels
the category labels
values
the bar heights
opts
chart options
Returns string
a complete SVG document
Throws Error
kind "plot" when labels / values are empty or unequal length, or the options are invalid

bars

jennifer
plot.bars(labels as list of string, data as list of Series, opts as Options)

A multi-series bar chart: one group of bars per labelled category. Each Series contributes its ys (one value per category) as a colour; series are drawn side by side ("grouped", opts.barMode) or on top of each other ("stacked"). Values may be negative (bars diverge from a zero baseline). A named series is listed in the legend.

labels
the category labels, drawn under each group
data
the series (each ys the same length as labels)
opts
chart options
Returns string
a complete SVG document
Throws Error
kind "plot" when labels / data are empty, a series length differs, or the options are invalid

chart

jennifer
plot.chart(data as list of Series, opts as Options)

Render one or more Series on shared axes, with a legend for named series. Each series draws per its mark (line / points / both / area), with optional dashing, marker shapes, and error bars. The domain spans every series, its error bars, and any reference-line value on a linear axis.

data
the series to plot (each non-empty, xs / ys equal length)
opts
chart options
Returns string
a complete SVG document
Throws Error
kind "plot" when data is empty, a series is malformed (lengths, an unknown mark / shape), the options are invalid, or a log axis sees a non-positive value

defaults

jennifer
plot.defaults()

Sensible defaults: a 640x400 canvas, no title / labels, blue data on white, a sans-serif 11px base font, gridlines and a top-right legend on, linear scales, grouped bars, tooltips on, no data labels, no reference lines.

Returns Options
the default options

floats

jennifer
plot.floats(xs as list of int)

Convert a list of int to a list of float, since the chart functions take float data and an int list does not match a float parameter.

xs
the integers
Returns list of float
the same values as floats

histogram

jennifer
plot.histogram(data as list of float, bins as int, opts as Options)

A histogram of data into bins equal-width buckets over the data range, drawing the bucket counts as adjacent bars.

data
the samples
bins
the number of buckets (>= 1)
opts
chart options
Returns string
a complete SVG document
Throws Error
kind "plot" when data is empty, bins is outside 1..10000, or the options are invalid

hline

jennifer
plot.hline(value as float, label as string)

A horizontal reference line at y = value (a threshold / target).

value
the y value
label
an optional caption ("" = none)
Returns RefLine
the reference line

line

jennifer
plot.line(xs as list of float, ys as list of float, opts as Options)

A line chart of a single series. A convenience over chart.

xs
the x coordinates
ys
the y coordinates
opts
chart options
Returns string
a complete SVG document
Throws Error
kind "plot" when xs / ys are empty or unequal length, or the options are invalid

points

jennifer
plot.points(name as string, xs as list of float, ys as list of float)

A points (scatter) series (mark "points").

name
the legend label
xs
the x coordinates
ys
the y coordinates
Returns Series
the series

save

jennifer
plot.save(svg as string, path as string)

Write an SVG chart string to a file, returning the path. A convenience over fs.writeString so plot.save(plot.line(...), "chart.svg") reads in one line. (Jennifer values have no methods, so it is plot.save($svg, path), not $svg.save(path).)

svg
the SVG document (from any chart function)
path
the destination file path
Returns string
the path written

scatter

jennifer
plot.scatter(xs as list of float, ys as list of float, opts as Options)

A scatter plot of a single series. A convenience over chart.

xs
the x coordinates
ys
the y coordinates
opts
chart options
Returns string
a complete SVG document
Throws Error
kind "plot" when xs / ys are empty or unequal length, or the options are invalid

series

jennifer
plot.series(name as string, xs as list of float, ys as list of float)

A line series (mark "line"). Set .mark / .color / .dash / .yErr / .shape on the result.

name
the legend label
xs
the x coordinates
ys
the y coordinates
Returns Series
the series

vline

jennifer
plot.vline(value as float, label as string)

A vertical reference line at x = value (a marker in time / along x).

value
the x value
label
an optional caption ("" = none)
Returns RefLine
the reference line

Structs

Options

Chart options: canvas size, captions, colours, fonts, margins, axis modes, legend placement, data labels, tooltips, and reference lines. Copy defaults() and set the fields you want.

jennifer
def struct Options {
    width as int,
    height as int,
    title as string,
    xLabel as string,
    yLabel as string,
    color as string,
    background as string,
    fontFamily as string,
    fontSize as int,
    grid as bool,
    legend as bool,
    legendPos as string,
    xLog as bool,
    yLog as bool,
    xDate as bool,
    dateFormat as string,
    marginLeft as int,
    marginRight as int,
    marginTop as int,
    marginBottom as int,
    barMode as string,
    barLabels as bool,
    hover as bool,
    refLines as list of RefLine
};
width
canvas width in pixels
height
canvas height in pixels
title
chart title, centred at the top ("" = none)
xLabel
x-axis caption ("" = none)
yLabel
y-axis caption, rotated ("" = none)
color
the default data colour (single-series line / scatter / bar)
background
the canvas background colour
fontFamily
the CSS font-family for all text
fontSize
the base tick-label size; the title and captions scale off it
grid
draw gridlines (false = short tick marks instead)
legend
draw a legend for named / multiple series
legendPos
"top-right" / "top-left" / "bottom-right" / "bottom-left"
xLog
log10 x scale (values must be positive)
yLog
log10 y scale (values must be positive)
xDate
treat x values as Unix seconds and label them as dates
dateFormat
strftime pattern for date labels ("" = chosen by tick spacing)
marginLeft
left margin (room for y labels)
marginRight
right margin
marginTop
top margin (room for the title)
marginBottom
bottom margin (room for x labels)
barMode
"grouped" or "stacked" for a multi-series bars chart
barLabels
draw the value above each grouped bar
hover
attach <title> tooltips to marks (native browser hover)
refLines
reference lines drawn over the data

RefLine

A reference line drawn across the plot at a constant value on one axis - a threshold, target, or marker.

jennifer
def struct RefLine {
    axis as string,
    value as float,
    label as string,
    color as string,
    dash as bool
};
axis
"y" for a horizontal line, "x" for a vertical one
value
the data value the line sits at
label
an optional caption drawn by the line ("" = none)
color
the line colour ("" = a default red)
dash
dashed (true) or solid

Series

One plotted data series. For line / scatter / area xs and ys are the coordinates; for bars only ys (the per-category values) is used. yErr, when the same length as ys, draws symmetric error bars (linear y only); shape picks the scatter marker.

jennifer
def struct Series {
    name as string,
    xs as list of float,
    ys as list of float,
    color as string,
    mark as string,
    dash as bool,
    yErr as list of float,
    shape as string
};
name
the legend label ("" = not listed)
xs
the x coordinates (unused by bars)
ys
the y coordinates / bar values
color
the series colour ("" = auto from the palette)
mark
"line" / "points" / "both" / "area"
dash
draw the line dashed
yErr
symmetric +/- error per point ([] = none)
shape
marker for points: "circle" / "square" / "triangle" / "diamond"