posit-dev / great-tables

Make awesome display tables using Python.
https://posit-dev.github.io/great-tables/
MIT License
1.43k stars 48 forks source link

fmt_nanoplot includes excluded rows when scaling plot #283

Open rasmi opened 2 months ago

rasmi commented 2 months ago

I am using fmt_nanoplot to create a table with a histogram on the margins. To do this, I want to exclude the last row, which is a Total row. When I exclude the row using the rows= parameter, the scale of the plot appears as if it still factors in the row that was not plotted. I would expect that the plot scales only with the values included in the plot.

Reproducible example

(adapted from docs) Screenshot 2024-04-12 14 20 51

import polars as pl
single_vals_df = pl.DataFrame(
    {
        "i": list(range(1, 6)),
        "lines_small": [12.44, 6.34, 5.2, -8.2, 10],
        "lines_large": [12.44, 6.34, 5.2, -8.2, 100]
    }
)
(
    GT(single_vals_df, rowname_col="i")
    .fmt_nanoplot(columns="lines_small", rows=[0,1,2,3], plot_type="line")
    .fmt_nanoplot(columns="lines_large", rows=[0,1,2,3], plot_type="line")
)

Development environment