Skip to content

polygon ​

Draws a closed polygon from explicit local-coordinate points. Useful for non-rectangular glyphs (trapezoids, arrows, custom shapes) that can't be expressed by the standard shape primitives.

python
from gofish import chart, polygon

chart([{}]).mark(
    polygon(
        points=[
            [0, 0],
            [60, 0],
            [50, 40],
            [10, 40],
        ],
        fill="steelblue",
    )
).render(w=100, h=60)

Signature ​

python
polygon(*, points=None, fill=None, stroke=None, stroke_width=None, opacity=None,
        debug=None) -> Mark

Keyword-only (matches every existing call site, which already passes points=... by keyword).

Parameters ​

A closed polygon defined by local-coordinate points (in the frame the polygon sits in: top-down on a plain canvas, upward inside a continuous y), given literally or read from a field. No dims channels — the bbox is computed from points.

OptionTypeDefaultDescription
pointslist | strRequired. Vertex list, at least 3 points — either a literal ring, or the name of a field holding one ring per row (which is how one mark draws a whole basemap).
fillstr"black"Fill color, or a field name for a color scale.
strokestrStroke color. Defaults to fill.
stroke_widthfloat0Stroke width in pixels.
opacityfloat1Opacity, 0 to 1, applied to both fill and stroke.
debugboolDev-only flag: logs this mark's key and datum to the console as it is built. It changes nothing about what is drawn.

Returns a Mark for use in .mark(). Call .name() on the result to make it referenceable via ref / select_all or a constraint.

Coordinates ​

Points are interpreted in the local coordinate system of whatever places the polygon — typically a layer or a constraint. The polygon's bounding box is the axis-aligned extent of its points; the parent placement system translates the whole polygon to position it.

Literal points are in the polygon's own frame. Where that frame's y reads top-down (a polygon placed by a layer or a constraint, outside any data-driven y), y grows downward like SVG, so a trapezoid whose wide edge sits at the bottom and narrow edge at the top is written:

python
polygon(
    points=[
        [10, 0],           # top-left   (inset)
        [width - 10, 0],   # top-right  (inset)
        [width, h],        # bottom-right (the wider edge)
        [0, h],            # bottom-left
    ],
)

Examples ​

python
# Trapezoidal weight glyph (from the pulley diagram)
polygon(
    points=[
        [0, 0],
        [width, 0],
        [width - 10, height],
        [10, height],
    ],
    fill="#545454",
).name("body")

# Triangle with stroke
polygon(
    points=[
        [0, 0],
        [40, 0],
        [20, 30],
    ],
    fill="transparent",
    stroke="black",
    stroke_width=2,
)

Data-driven fill ​

fill and stroke work as they do on rect. A field name reads that field off each row and sends it through the chart's color scale. Any other string is a literal color. When stroke is omitted it follows the fill.

python
chart(rows, color=gradient(["#fff5eb", "#7f2704"])).mark(
    polygon(points="ring", fill="n")
)

Here points="ring" names a field holding one ring per row, so the mark draws one polygon per row, each colored by its own n.

Notes ​

  • The polygon is always closed — the last point connects back to the first automatically.