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

Ensure that reference lines appear in single value bar/line plots #307

Open rich-iannone opened 2 months ago

rich-iannone commented 2 months ago

Right now the reference_line= argument does not display a reference line when making a nanoplot from a single value. From question in the gt_package Discord channel, @MarcoGorelli asked to make this example work (and I filled in the GT part here):

import polars as pl
from great_tables import GT

data = pl.DataFrame({
    'Library': ['pandas (including NumPy)', 'pandas (including NumPy and PyArrow)', 'Polars'],
    'Size (MB)': [163, 290, 85],
}).sort('Size (MB)')

GT(data).fmt_nanoplot(columns="Size (MB)", plot_type="bar", reference_line=275)

Currently this results in:

nanoplot_polars

The desired result should instead be something like this:

fmt-nanoplot-ref-line-target
marcozzxx810 commented 1 month ago

@rich-iannone, I have tried out to use reference_line="min", resulting the same graph.

image

does it supposed to work when using keywords?

import polars as pl
from great_tables import GT

data = pl.DataFrame({
    'Library': ['pandas (including NumPy)', 'pandas (including NumPy and PyArrow)', 'Polars'],
    'Size (MB)': [163, 290, 85],
}).sort('Size (MB)')

GT(data).fmt_nanoplot(columns="Size (MB)", plot_type="bar", reference_line="min")