在matplotlib中使用pgf的非斜体刻度标签

时间:2017-02-21 15:05:09

标签: python matplotlib latex pgf

我使用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或其他图片格式不同。

0 个答案:

没有答案
相关问题