Skip to content
Halyard
Project
Source code on Codeberg (opens in new tab)

Search

Menu

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 halyard-web playground.

Mark types

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

Example

halyard
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:
halyard
df |> Plot.draw Point { x: @weight, y: @hp } |> Plot.color @origin

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:
halyard
df |> Plot.draw PlotType::Point enc

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:
halyard
Plot.hconcat [chart_a, chart_b]

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:
halyard
chart |> Plot.height 400

See also: Plot.width, Plot.title

Plot.layer

[Chart] -> Chart

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

Example:
halyard
Plot.layer [chart1, chart2]

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:
halyard
df |> Plot.draw Point { x: @weight, y: @hp } |> Plot.size @cylinders

See also: Plot.draw, Plot.color

Plot.title

String -> Chart -> Chart

Set the chart title.

Example:
halyard
chart |> Plot.title "Cars dataset"

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:
halyard
chart |> Plot.to_json

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:
halyard
Plot.vconcat [chart_top, chart_bottom]

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:
halyard
chart |> Plot.width 800

See also: Plot.height, Plot.title