I am using the pgf
backend in matplotlib 1.5.3
to produce publication-quality figures. Here is how I set up the plotting script.
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")
I am using the package sfmath
to set all math environments in sans-serif
. At the end I save in .pdf
and .eps
format. Here's the problem: While the pdf
clearly uses sans-serif
font everywhere, the eps
file uses serif
for all tick labels (not axis labels)! When I modify my LaTeX template to use sfmath
it does not change the tick labels.
How can I prevent the eps
from using serif
font in the tick labels?
Edit: After a good day of experimenting, the only (barely) satisfying solution I found was to use .tiff
as format, since this is also allowed by the journal. eps
just seems to have problems and always turns out different than the pdf
or other image formats.