Skip to content

line

Connects data points with a line. A line draws through a set of points, so it is most often paired with selectAll() to trace a layout produced by another chart. selectAll hands line an array of refs, and the line reads placed geometry off them.

python
from gofish import layer, chart, scatter, blank, selectAll, line

layer([
    chart(catch_locations)
        .flow(scatter(by="lake", x="x", y="y"))
        .mark(blank().name("points")),
    chart(selectAll("points")).mark(line()),
]).render(w=500, h=300, axes=True)

Signature

python
line(stroke=None, strokeWidth=None, opacity=None, curve=None) -> Mark

Parameters

ParameterTypeDescription
strokestrLine color
strokeWidthintLine width in pixels
opacityfloatOpacity, 01
curvestr | dictPath shape; default "auto", which auto-smooths continuous line charts

Returns a Mark for use in .mark().

The line pattern

A line needs points to connect. The idiomatic recipe:

  1. One chart positions invisible blank marks and names the layer with .name("points").
  2. A second chart selects that layer — chart(selectAll("points")) — and draws a line() through it.
  3. layer([...]) composes the two.

This separation lets the same positioned points back both a line and, say, circles drawn on top.

Sugar: .connect()

When the line connects a chart's own marks, skip the two-chart selectAll recipe and chain .connect() on the builder:

python
chart(data).flow(
    scatter(by="lake", x="x", y="y")
).mark(circle()).connect(line(stroke="steelblue", strokeWidth=2))

See .connect() for the full semantics; the explicit layer([...]) + selectAll form connects another chart's marks.

Examples

python
# Styled line
chart(selectAll("points")).mark(line(stroke="black", strokeWidth=2))