Skip to content

Mapping value ranges to colours #359

Answered by jrycw
david-waterworth asked this question in Q&A
Discussion options

You must be logged in to vote

@david-waterworth, here's a reference solution that came to mind.

import polars as pl
from great_tables import GT, html, style, loc
from great_tables.data import towny


towny_mini = pl.from_pandas(towny).head(10)

(
    GT(
        towny_mini[["name", "land_area_km2"]],
        rowname_col="name",
    )
    .tab_header(
        title="The Municipalities of Ontario",
        subtitle="The top 10 highest population density in 2021",
    )
    .tab_stubhead(label="Municipality")
    .fmt_number(columns=["land_area_km2"], decimals=1)
    .cols_label(
        land_area_km2=html("land area, <br>km<sup>2</sup>"),
    )
    .tab_style(
        style=style.fill(color="red"),
        locations=loc.b…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by david-waterworth
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants