Skip to content
Internals

flow

Applies a pipeline of operators to the chart's data. Operators partition, position, and transform the data before the mark draws it.

python
from gofish import chart, spread, stack, rect

chart(seafood).flow(
    spread(by="lake", dir="x"),
    stack(by="species", dir="y", label=False),
).mark(rect(h="count", fill="species")).render(w=500, h=300, axes=True)

Signature

python
ChartBuilder.flow(*operators) -> ChartBuilder

Parameters

ParameterTypeDescription
*operatorsOperatorOne or more operators, applied left to right

Returns a new ChartBuilder with the operators appended.

How it works

Operators run in order. Each one receives the data (or groups) produced by the previous one. In the example above:

  1. spread(by="lake", dir="x") splits the rows into one group per lake and places the groups across the x axis.
  2. stack(by="species", dir="y") stacks each lake's rows by species along y.

The mark then draws every leaf row.

Available operators

OperatorPurpose
spreadLay groups out along an axis, with gaps
stackStack groups edge-to-edge along an axis
tableLay groups out in a 2D grid
scatterPosition groups by x/y fields
groupWrap each partition in a frame
deriveTransform the data with a Python function
logPrint the data for debugging

Notes

  • flow() can be called multiple times; operators accumulate.
  • A chart with no flow() draws a single mark over the whole dataset.