matplotlibrc和Latex软件包设置

时间:2018-08-03 13:39:42

标签: python matplotlib configuration latex configuration-files

如何在python中设置乳胶包装选项?

我正在尝试设置siunitx。我不知道如何设置选项。这也直接适用于matplotlibrc。 以下无效。

import matplotlib as mpl

mpl.rc('text', usetex=True)
mpl.rcParams['text.latex.preamble'] = '\usepackage[range-units = single,range-phrase={-}]{siunitx}'
## using the following instead of the previous line works...
# mpl.rcParams['text.latex.preamble'] = '\usepackage[range-units = single]{siunitx},\sisetup{range-phrase={-}}'

import numpy as np
import matplotlib.pyplot as plt

x=np.linspace(1,100,1)
y=x
fig=plt.figure()
ax=fig.add_subplot(111)
ax.plot(x,y,label=r'\SIrange{0}{1}{\metre\per\second}')
ax.legend(loc=0)

由于代码段有效,因此我建议这是由于使用了逗号引起的。我没有运气就尝试过\,','。我在jupyter notebook的Mac上尝试过。
在默认的matplotlibrc中,它说

#text.latex.preamble :      ## IMPROPER USE OF THIS FEATURE WILL LEAD TO LATEX FAILURES
                            ## AND IS THEREFORE UNSUPPORTED. PLEASE DO NOT ASK FOR HELP
                            ## IF THIS FEATURE DOES NOT DO WHAT YOU EXPECT IT TO.
                            ## preamble is a comma separated list of LaTeX statements
                            ## that are included in the LaTeX document preamble.
                            ## An example:
                            ## text.latex.preamble : \usepackage{bm},\usepackage{euler}
                            ## The following packages are always loaded with usetex, so
                            ## beware of package collisions: color, geometry, graphicx,
                            ## type1cm, textcomp. Adobe Postscript (PSSNFS) font packages
                            ## may also be loaded, depending on your font settings 

很遗憾,除了注释中指定的内容外,我找不到有关此选项正确用法的任何信息。

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

我希望这有助于将前导字符串包含在列表中。

mpl.rcParams['text.latex.preamble'] = ['\usepackage[range-units=single,range-phrase={-}]{siunitx}']