【发布时间】:2018-06-22 20:38:09
【问题描述】:
使用this accepted answer as a reference,我一直在尝试复制 pandas DF to TeX to PDF to png 配方。但是,我的 Python 3(通过 Anaconda Navigator 使用 Jupyter Notebook)给我带来了一些麻烦。
我已将 MiKTeX 安装在本地磁盘的以下默认位置:
C:\Users\USERNAME\AppData\Local\Programs\MiKTeX\2.9
我还在以下位置安装了 LaTex:
C:\Users\USERNAME\AppData\Local\Programs\Python\Python36-32\Lib\site-packages\notebook\static\components\MathJax\extensions\TeX
但是,当我使用我的 Pandas df 对象运行代码块时:
filename = 'out.tex'
pdffile = 'out.pdf'
outname = 'out.png'
template = r'''\documentclass[preview]{{standalone}}
\usepackage{{booktabs}}
\begin{{document}}
{}
\end{{document}}
'''
with open(filename, 'wb') as f:
f.write(bytes(template.format(df.to_latex()),'UTF-8'))
subprocess.call(['pdflatex', filename], shell=True)
subprocess.call(['convert', '-density', '300', pdffile, '-quality', '90', outname])
它只是返回“4”,从我原来的 df 创建的唯一文件是“out.tex”。我希望将 DF 转换为 png 图像,这样我就可以将整个过程保存在我的 Notebook 脚本中。
任何建议将不胜感激。谢谢。
【问题讨论】:
标签: python pandas latex pdflatex