Esc
Start typing to search...

Plot Module

Vega-Lite chart construction.

Plot.draw df PlotType { x: @col, y: @col } produces a Chart that renders inline in Jupyter notebooks and the keel-web playground.

Mark types

ConstructorVega-Lite mark
Point"point"
Line"line"
Bar"bar"
Histogram"bar" (with bin: true)
Rect"rect"

Example

import Plot

df
  |> Plot.draw Point { x: @weight, y: @hp }
  |> Plot.color @origin
  |> Plot.title "Cars dataset"

Functions

Plot.color

DataFrameColumn -> Chart -> Chart

Add a color encoding channel to an existing chart.

Example:
df |> Plot.draw Point { x: @weight, y: @hp } |> Plot.color @origin
Try it

See also: Plot.draw, Plot.size

Plot.draw

PlotType -> { x: DataFrameColumn, y: DataFrameColumn } -> DataFrame -> Chart

Construct a Vega-Lite v5 chart from a mark type, an encoding record, and a DataFrame.

Example:
df |> Plot.draw PlotType::Point enc
Try it

Notes: All three arguments are required and type-checked at compile time. Missing any one produces a compile-time arity or TypeMismatch error, not a runtime failure.

See also: Plot.color, Plot.title, Plot.layer

Plot.hconcat

[Chart] -> Chart

Place charts side by side horizontally (Vega-Lite hconcat).

Example:
Plot.hconcat [chart_a, chart_b]
Try it

Notes: Raises a runtime error for an empty list.

See also: Plot.layer, Plot.vconcat

Plot.height

Int -> Chart -> Chart

Set the chart height in pixels.

Example:
chart |> Plot.height 400
Try it

See also: Plot.width, Plot.title

Plot.layer

[Chart] -> Chart

Compose a non-empty list of charts as overlapping layers (Vega-Lite layer).

Example:
Plot.layer [chart1, chart2]
Try it

Notes: Raises a runtime error for an empty list.

See also: Plot.hconcat, Plot.vconcat

Plot.size

DataFrameColumn -> Chart -> Chart

Add a size encoding channel to an existing chart.

Example:
df |> Plot.draw Point { x: @weight, y: @hp } |> Plot.size @cylinders
Try it

See also: Plot.draw, Plot.color

Plot.title

String -> Chart -> Chart

Set the chart title.

Example:
chart |> Plot.title "Cars dataset"
Try it

See also: Plot.width, Plot.height

Plot.to_json

Chart -> String

Serialise a Chart to its Vega-Lite v5 JSON spec as a pretty-printed string.

Example:
chart |> Plot.to_json
Try it

Notes: Use this to embed the spec in compliance manifests or pass it to external renderers.

See also: Plot.draw

Plot.vconcat

[Chart] -> Chart

Stack charts vertically (Vega-Lite vconcat).

Example:
Plot.vconcat [chart_top, chart_bottom]
Try it

Notes: Raises a runtime error for an empty list.

See also: Plot.layer, Plot.hconcat

Plot.width

Int -> Chart -> Chart

Set the chart width in pixels.

Example:
chart |> Plot.width 800
Try it

See also: Plot.height, Plot.title