Libertine font in Matplotlib?

I use the following lines in my preamble to create beamer
slides:\usepackage{libertine} % For the Biolinum sans-serif
font\usepackage[libertine]{newtxmath} % For the Libertine-compatible math
font\usepackage[T1]{fontenc} % To choose T1 font encondingWhen I place plots
created using matplotlib in these slides, I would like to use the same fonts
in the plots to maintain the same look and style. I'm however having trouble
with the math font loaded using the newtxmath package used in matplotlib.
The following code snippets illustrate the problem:import matplotlib.pyplot
as pltplt.rcParams['font.size'] = 20plt.rcParams['text.usetex'] =
Trueplt.rcParams['text.latex.preamble'] =
equation: \alpha x + \beta y + \gamma z = \theta$') the
following plot:
Note the incorrect character spacing and serifs on the characters. If I
slightly tweak the text.latex.preamble parameter to the following (sfmath
included in addition):plt.rcParams['text.latex.preamble'] =
get the expected result:
<> Why is
this happening? Why does sfmath need to be included to get the expected
result? Regular pdflatex compilation of beamer slides produces the same
result without including the sfmath package.


View this message in context:
Sent from the matplotlib - users mailing list archive at
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>