Skip to content

render ​

Renders the chart as an anywidget that displays in Jupyter, JupyterLab, VS Code notebooks, and marimo.

python
from gofish import chart, spread, rect

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

Signature ​

python
ChartBuilder.render(w=800, h=600, axes=None, legend=None, debug=False)

layer([...]) (a mark), .layer(...) chains (LayerBuilder) and bare marks take the same options. They are the JS .render(container, options) options, in snake case.

Parameters ​

ParameterTypeDefaultDescription
wint800Width of the whole graphic in pixels, axes, titles and legend included
hint600Height of the whole graphic in pixels, axes, titles and legend included
axesbool | dict | NoneNoneAuto-generate axes, labels, and legends; same shape as chart(axes=...). Overrides the outermost chart's axes only. Unset, the chart's own axes option decides.
legendbool | dict | NoneNoneWhich legend entries to draw: True, False, or a dict such as {"color": False}; see chart › Legend. Unset, the default (True) applies. A chart() option of the same name wins over this one.
debugboolFalseWhether to enable debug rendering

Returns a GoFishChartWidget.

Axes on the chart or on render

axes can be passed to chart or to render, as in JS (chart(data, { axes: true }) or .render(container, { axes: true })). See chart for the full axes shape. A combinator rendered with no axes draws no axes of its own, and each chart inside it draws its own axes and titles, as it would rendered alone.

Automatic display ​

A ChartBuilder displays itself when it is the last expression in a notebook cell — no .render() call is required:

python
chart(seafood).flow(spread(by="lake", dir="x")).mark(rect(h="count"))

This is equivalent to calling .render() with its defaults. Call .render() explicitly when you want to set the size or other render options:

python
chart(seafood, axes=True).flow(spread(by="lake", dir="x")).mark(
    rect(h="count")
).render(w=500, h=300)

Inspecting the IR ​

.to_ir() returns the chart's intermediate representation document (its root and its tables as JSON rows) instead of rendering — useful for debugging or testing:

python
chart(seafood).flow(spread(by="lake", dir="x")).mark(rect(h="count")).to_ir()

Layout warnings ​

When a chart cannot fit its canvas, the render keeps its size, draws the chart anyway, and warns, as in JS (see render › Layout warnings). Once the widget has rendered, widget.warnings is a list with one dict per warning, with the keys kind, node, axis, needed, available, parts and message. The browser console also prints each one, prefixed [gofish:layout].

python
w = chart(barley).flow(
    spread(by="site", dir="x", spacing=110),
    spread(by="year", dir="x", spacing=36),
    scatter(by="variety", y="yield"),
).mark(line(stroke="variety")).render(w=700, h=350)   # display this cell

# In a later cell, after it has rendered:
for warning in w.warnings:
    print(warning["message"])

Notes ​

  • Rendering requires a notebook kernel — render() produces a widget. To get an SVG file or string, use save / to_svg.
  • A chart must have a mark before it can be rendered.