Matplotlib latex working directory / search path

只愿长相守 提交于 2019-12-04 05:00:48

I'm having the same error on my Ubuntu Lucid, matplotlib 1.1.0. There are two options:

Giving it a full path:

matplotlib.rcParams['text.latex.preamble'] = r'\input{/home/br/sweethome/temp/BigFatHeader}'

works for me. Notice that you don't put .tex extension for the files to be \input. If you don't want to hardcode the path, you can get it using os.getcwd():

import matplotlib
import matplotlib.pyplot as plt
import os

filename=r'\input{'+os.getcwd()+r'/BigFatHeader}'

matplotlib.rcParams['text.latex.preamble'] = filename
matplotlib.rcParams['text.usetex'] = True
plt.plot([1,2])
plt.savefig('MWE.pdf')

Or just read in your your file into a text string and set the rcParams with it.

import matplotlib
import matplotlib.pyplot as plt

paramstring=r'\usepackage{bm}'
matplotlib.rcParams['text.latex.preamble'] = paramstring
matplotlib.rcParams['text.usetex'] = True
plt.plot([1,2])
plt.savefig('MWE.pdf')
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!