dexplo / dataframe_image

A python package for embedding pandas DataFrames as images into pdf and markdown documents
https://dexplo.org/dataframe_image
MIT License
282 stars 41 forks source link

In latest version, figure size is too big even if I use "dpi=800, fontsize=3.8" #110

Closed yun881201 closed 9 months ago

yun881201 commented 10 months ago

Hello. I recently reinstalled dataframe-image. However, unlike before, even if "dpi=800, fontsize=3.8" code is used, the image size cannot be reduced while maintaining good image quality. How can I do this?

PaleNeutron commented 10 months ago

Can you provide a minimal reproduce example?

yun881201 commented 10 months ago

Chrome : 120.0.6099.217 jupyter-book : 0.15.1 dataframe-image : 0.2.3

The followings are cells written in the testing jupyter notebook and I converted the notebook to a latex pdf by using jupyter-book. I attached the resulted pdf file. As you can see, the figures in the pdf are all too big or have bad quality. _val.pdf

cell1 : code cell

import pandas as pd
import dataframe_image as dfi

cell2 : code cell

data = {'Name': ['Tom', 'nick', 'krish', 'jack'],
'Age': [20, 21, 19, 18]}
df = pd.DataFrame(data)
df

cell3 : code cell

figname = 'test'
dfi.export(df, 'figure/{}.png'.format(figname))

cell4 : md cell ![test](figure/test.png)

cell5 : code cell

figname = 'test1'
dfi.export(df, 'figure/{}.png'.format(figname), fontsize=3.8, dpi=800)#, fontsize=12)#, fontsize=4, dpi=800)

cell6 : md cell ![test1](figure/test1.png)

cell7 : code cell

figname = 'test2'
dfi.export(df, 'figure/{}.png'.format(figname), fontsize=1, dpi=800)

cell8 : md cell ![test1](figure/test2.png)

cell9 : code cell

figname = 'test3'
dfi.export(df, 'figure/{}.png'.format(figname), dpi=70)

cell10: md cell ![test1](figure/test3.png)

PaleNeutron commented 10 months ago

High dpi and very small fontsize is used in early version which adopt a bug in Chrome version 111. And I have tried your code with version 0.1.12 it looks like the same.

I think you should export image with dpi 300 and resize it as documented in https://jupyterbook.org/en/stable/content/figures.html

yun881201 commented 9 months ago

Based on PaleNeutron comment, I solved my problem. I used the following code: For dpi 300,

```{image} figure/filename.png
:scale: 19%
:name: filename