[Matplotlib-users] Libertine font in Matplotlib?

ragnarok reaganf2 at gmail.com
Tue Dec 8 07:08:45 EST 2015


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'] =
'\usepackage{libertine},\usepackage[libertine]{newtxmath},\usepackage[T1]{fontenc}'plt.axes()plt.title(r'$Mathematical\
equation: \alpha x + \beta y + \gamma z = \theta$')plt.show()produces the
following plot:
<http://matplotlib.1069221.n5.nabble.com/file/n46524/without_sfmath.png>
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'] =
'\usepackage{libertine},\usepackage[libertine]{newtxmath},\usepackage{sfmath},\usepackage[T1]{fontenc}'I
get the expected result:
<http://matplotlib.1069221.n5.nabble.com/file/n46524/with_sfmath.png> 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: http://matplotlib.1069221.n5.nabble.com/Libertine-font-in-Matplotlib-tp25347p46524.html
Sent from the matplotlib - users mailing list archive at Nabble.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20151208/7a1075ea/attachment.html>


More information about the Matplotlib-users mailing list