Mapping value ranges to colours #359
Answered
by
jrycw
david-waterworth
asked this question in
Q&A
-
I know you can use |
Beta Was this translation helpful? Give feedback.
Answered by
jrycw
May 23, 2024
Replies: 1 comment
-
@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.body(
columns="land_area_km2",
rows=pl.col("land_area_km2").lt(pl.col("land_area_km2").quantile(0.8)),
),
)
.tab_style(
style=style.fill(color="orange"),
locations=loc.body(
columns="land_area_km2",
rows=pl.col("land_area_km2").ge(pl.col("land_area_km2").quantile(0.8)),
),
)
.tab_style(
style=style.fill(color="green"),
locations=loc.body(
columns="land_area_km2",
rows=pl.col("land_area_km2").ge(pl.col("land_area_km2").quantile(0.95)),
),
)
) |
Beta Was this translation helpful? Give feedback.
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
@david-waterworth, here's a reference solution that came to mind.