[Python] transparent background for Great Tables in python

Discussão em 'Python' iniciado por Stack, Março 12, 2025.

  1. Stack

    Stack Membro Participativo

    I would like to make the background of the table transparent but am not able to do so. I've tried using hex codes, rgb, and literal colour labels.

    I tried tweaking using .tab_style and also .tab_options.

    import polars as pl
    import polars.selectors as cs

    from great_tables import GT, md, html, style, loc
    from great_tables.data import airquality

    airquality_mini = airquality.head(20).assign(Year = 1973)
    pl_airquality = pl.DataFrame(airquality_mini).select(
    "Year", "Month", "Day", "Ozone", "Solar_R", "Wind", "Temp"
    )
    gt_air = GT(pl_airquality)

    (
    gt_air

    .tab_style(
    style=
    [
    style.fill(color="rgba(0, 0, 0, 0)"),
    style.text(font="Arial")
    ],
    locations=
    [
    loc.subtitle(),
    loc.title()
    ]
    )

    .tab_header(
    title = md("**New York Air Quality Measurements**"),
    subtitle = "Daily measurements in New York City (May 1-10, 1973)"
    )

    .opt_table_font(font=["Corbel"])

    # Table styles ----
    .tab_style(
    style.fill("lightyellow"),
    loc.body(
    columns = cs.all(),
    rows = pl.col("Wind") == pl.col("Wind").max()
    )
    )
    .tab_style(
    style.text(weight = "bold"),
    loc.body("Wind", pl.col("Wind") == pl.col("Wind").max())
    )

    .save(
    file = "tweakable.png",
    scale = 1.0,
    web_driver = "chrome"
    )
    )



    I have attached a failed output of the table.

    [​IMG]

    Continue reading...

Compartilhe esta Página