Rect heatmap

A dense quantitative grid rendered with rect marks and a continuous color scale.

Inputs and adaptation

Field

Type

Meaning

x

Ordered category

Column identifier.

y

Ordered category

Row identifier.

z

Quantitative

Prepared cell value.

Replace the internal heatmap_data() fixture with your prepared long-form table: one row per x/y pair. Update fields, category order, palette, domain and color title together. Distinguish missing cells from observed zeros. Enable native axes when row/column labels are needed; this example deliberately hides them.

Expected here: a 40-column by 20-row grid with quantitative color. Python loads the prepared synthetic table; no browser-side calculation is declared.

Code

"""Rect heatmap.

A dense quantitative grid rendered with rect marks and a continuous color
scale.
"""

import genome_spy as gs
from genome_spy.datasets._grammar import heatmap_data
from genome_spy.schema import Scale


# Load a small grid of example values.
data = heatmap_data()

# Draw one colored tile per cell, with color showing its value.
chart = (
    gs.Chart(data)
    .mark_rect()
    .encode(
        x=gs.X("x:O").axis(None),
        y=gs.Y("y:O").axis(None),
        color=gs.Color("z:Q").scale(Scale(scheme="magma")).title("value"),
    )
    .properties(title="Rect heatmap")
)