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
| Constructor | Vega-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.
df |> Plot.draw Point { x: @weight, y: @hp } |> Plot.color @originTry itPlot.draw
PlotType -> { x: DataFrameColumn, y: DataFrameColumn } -> DataFrame -> Chart
Construct a Vega-Lite v5 chart from a mark type, an encoding record, and a DataFrame.
df |> Plot.draw PlotType::Point encTry itNotes: 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).
Plot.hconcat [chart_a, chart_b]Try itNotes: 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.
chart |> Plot.height 400Try itSee also: Plot.width, Plot.title
Plot.layer
[Chart] -> Chart
Compose a non-empty list of charts as overlapping layers (Vega-Lite layer).
Plot.layer [chart1, chart2]Try itNotes: 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.
df |> Plot.draw Point { x: @weight, y: @hp } |> Plot.size @cylindersTry itSee also: Plot.draw, Plot.color
Plot.title
String -> Chart -> Chart
Set the chart title.
chart |> Plot.title "Cars dataset"Try itSee 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.
chart |> Plot.to_jsonTry itNotes: 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).
Plot.vconcat [chart_top, chart_bottom]Try itNotes: 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.
chart |> Plot.width 800Try itSee also: Plot.height, Plot.title