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) -> MarkParameters
| Parameter | Type | Description |
|---|---|---|
stroke | str | Line color |
strokeWidth | int | Line width in pixels |
opacity | float | Opacity, 0–1 |
curve | str | dict | Path 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:
- One chart positions invisible
blankmarks and names the layer with.name("points"). - A second chart selects that layer —
chart(selectAll("points"))— and draws aline()through it. 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))