0

我想使用 imgkit 导出带有条形图(https://pandas.pydata.org/pandas-docs/stable/user_guide/style.html#Bar-charts)的熊猫df,如下所示,但条形图不包含在最终.pdf

在此处输入图像描述

我尝试使用css=<filename>kwarg 将 css 单独传递给 webkit,但没有成功。样式手册中的其他样式 pd.DataFrames 似乎有效。

有人知道为什么不应用 CSS 吗?将样式表导出为 png 的任何替代方法?

import pandas as pd
import numpy as np

np.random.seed(24)
df = pd.DataFrame({'A': np.linspace(1, 10, 10)})
df = pd.concat([df, pd.DataFrame(np.random.randn(10, 4), columns=list('BCDE'))],
               axis=1)
df.iloc[3, 3] = np.nan
df.iloc[0, 2] = np.nan

s = df.style.bar(subset=['A', 'B'], align='mid', color=['#d65f5f', '#5fba7d'])
html = s.render()

import imgkit
imgkit.from_string(html, 'styled_table3.png')
4

0 回答 0