Matplotlib in Latex documents

Hi,

I'm having trouble when creating plots for use in latex documents. I tried
several methods, but the fonts are always inconsistent in size and weight. I
thought the "text.usetex" option to provide a result closest to the latex
document I want to include the plots in, but this minimal example shows that
there is some weird behavior of matplotlib producing bold fonts by default:

import pylab as p
params_text = {
               'text.usetex': True,
}
p.rcParams.update(params_text)
X = range(10)
Y = [x**2 for x in X]
p.plot(X, Y)
p.xlabel(ur"$\rm{time}$ \rm{time} time (s $10^3$)")
p.show()

In a normal latex document, the words within the xlabel should look the
same. The "correct" font style seems to be the one within the math mode.
Unfortunately the usetex option produces pdf files 10x larger, but without
it, the text looks even more distorted.

I get best results in terms of appearance and size when producing eps files
with the usedistiller xpdf option and then manually convert eps to pdf. But
still, the default fonts are too bold although the weight was never altered.

···

--
View this message in context: http://old.nabble.com/Matplotlib-in-Latex-documents-tp33746279p33746279.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

I use the following setup (under Ubuntu, in case that matters):

params = {'backend': 'Agg',
          'ps.usedistiller' : 'xpdf',
          'text.usetex' : True,
          'font.family': 'serif',
          'font.serif' : ['Times'],
          }
mpl.rcParams.update(params)

I am not sure if all of them are necessary.

I made all the figures in this paper using these parameters:
http://arxiv.org/pdf/1110.5063v1

Alejandro.

···

On Wed, Apr 25, 2012 at 6:54 AM, Peter Würtz <pwuertz@...982...> wrote:

I'm having trouble when creating plots for use in latex documents.

This looks much better indeed. I played around a bit and found that only the removal of the default serif fonts was needed to fix the appearance.

Using these options

'text.usetex' : True,
'font.family': 'serif',
'font.serif' : [],

everything looks fine now. It seems that there is some default font that messes up the latex output.

Bug?

···

On 04/25/2012 04:06 PM, Alejandro Weinstein wrote:

I use the following setup (under Ubuntu, in case that matters):

params = {'backend': 'Agg',
           'ps.usedistiller' : 'xpdf',
           'text.usetex' : True,
           'font.family': 'serif',
           'font.serif' : ['Times'],
           }
mpl.rcParams.update(params)