dexplo / dataframe_image

A python package for embedding pandas DataFrames as images into pdf and markdown documents

Home Page:https://dexplo.org/dataframe_image

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Column size calculation needs to be user adjustable.

Erotemic opened this issue · comments

It looks like there are some heuristics in the code that computes column sizes when rendering the HTML to an image. The following MWE shows the issue I'm running into:

import dataframe_image as dfi
import pandas as pd

text = '{"Eval 21":{"pipe":"BAS+SC","bas_pxl.model.channels":"(L8,PD,S2,WV):BGR","bas_pxl.package_fpath":"Drop8_Median10GSD_allsensors_<tuned>_V7_epoch187_step2632","bas_poly.thresh":0.35,"bas_poly.time_thresh":0.8},"Eval 21b":{"pipe":"BAS","bas_pxl.model.channels":"(L8,PD,S2,WV):BGR","bas_pxl.package_fpath":"Drop8_ARA_Median10GSD_allsensors_pointannsv1_v1_epoch56_step4788","bas_poly.thresh":0.39,"bas_poly.time_thresh":0.75}}'
df = pd.read_json(text)
fpath = 'foo.png'
dfi.export(
    df.style,
    fpath,
    table_conversion='matplotlib',
    fontsize=12,
    max_rows=-1,
    dpi=None,
)
import subprocess
subprocess.call(f'eog {fpath}', shell=True)

This results in a column being cutoff:

foo

If I mess with the fontsize I can get it to work reasonably well. But it would be nicer to either fix the heuristics to work in this case (which may not be possible, I've glanced at them, but haven't seen if they attempt to always well-size the columns), or give the user some means to adjust the multiplier used on each column or something like that.

I'd like to put in a fix for this, but I need feedback on what the right API should be.

If you mean the second cell of index column is cutoff, I think you could refer this fix #90

I fix bold column header width but I'm not should if it applied to all cell.