我正在使用pgf
后端matplotlib 1.5.3
来生成出版质量的数字。这是我设置绘图脚本的方法。
import matplotlib as mpl
mpl.use('pgf')
pgf_with_latex = { # setup matplotlib to use latex for output
"pgf.texsystem": "pdflatex", # change this if using xetex or lautex
"text.usetex": True, # use LaTeX to write all text
"font.family": "sans-serif",
"font.sans-serif": "Bitstream Vera Sans, Helvetica, Computer Modern Sans Serif",
"pgf.preamble": [
r"\usepackage[utf8x]{inputenc}", # use utf8 fonts because your computer can handle it :)
r"\usepackage[T1]{fontenc}", # plots will be generated using this preamble
r"\usepackage{textcomp}",
r"\usepackage{sfmath}", # sets math in sans-serif
]
}
mpl.rcParams.update(pgf_with_latex)
import matplotlib.pyplot as plt
def newfig():
plt.clf()
fig = plt.figure(figsize=(4, 2))
ax = fig.add_subplot(111)
return fig, ax
fig, ax = newfig()
ax.set_xlabel("Some x-label text")
plt.gcf().tight_layout()
plt.savefig(os.getcwd() + "/test.pdf")
plt.savefig(os.getcwd() + "/test.eps")
我正在使用该包sfmath
将所有数学环境设置为sans-serif
. 最后我保存.pdf
并.eps
格式化。这就是问题所在:虽然在任何地方都pdf
清楚地使用sans-serif
字体,但该eps
文件serif
用于所有刻度标签(不是轴标签)!当我修改我的 LaTeX 模板以使用sfmath
它时,它不会更改刻度标签。
如何防止在刻度标签中eps
使用serif
字体?
编辑:经过一整天的试验,我发现唯一(勉强)令人满意的解决方案是使用.tiff
格式,因为期刊也允许这样做。eps
只是似乎有问题,并且总是与pdf
其他图像格式不同。