On 06/09/2012 14:49, Benjamin Root wrote:


On Thu, Sep 6, 2012 at 6:54 AM, Mogliii <mogl...@gmx.net> wrote:
Hi,

I am preparing figures with the following matplotlib preamble:

plt.rc('font', **{'family':'serif', 'serif':['Computer Modern Roman'],
                  'monospace':['Computer Modern Typewriter']})
params = {'backend': 'ps',
          'text.latex.preamble': [r"\usepackage{upgreek}",
                                  r"\usepackage[nice]{units}"],
          'axes.labelsize': 12,
          'text.fontsize': 12,
          'legend.fontsize': 8,
          'xtick.labelsize': 10,
          'ytick.labelsize': 10,
          'text.usetex': True,
          'figure.figsize': fig_size,
          'axes.unicode_minus': True}
plt.rcParams.update(params)


But when using subscript and superscript in math mode the sizes end up different than in my LaTeX document (my .cls is using "book" as base class).

Attached are two screenshots of it rendered from matplotlib and from Latex (sorry for the different sizes). The "mean" is clearly of different size in relation to the "d".


Is there an option to specify a .cls file in rcParams that should be used for rendering?
I tried:
text.latex.preamble': [r"\documentclass[twoside]{mycls}",
                                  r"\usepackage{upgreek}",
                                  r"\usepackage[nice]{units}"],
but then I get the error:
! LaTeX Error: Two \documentclass or \documentstyle commands.

How to overwrite default matplotlib one? my matplotlibrc has a commented preamble.



See also my question on tex.stackexchange.com: http://tex.stackexchange.com/questions/70400/subscript-size-different-in-latex-and-matplotlib



Many thanks


This might have been fixed at one point.  Which version of matplotlib are you using?

Ben Root


I found the solution. My LaTeX file uses the package amsmath, which also loads amstext. And that is invoked when using \text{} or \textnormal{} inside a formula.

So the solution in matplotlib is to add the following to the preamble:
'text.latex.preamble': [r"\usepackage{upgreek}",
                                  r"\usepackage[nice]{units}",
                                  r"\usepackage{amstext}"],

I was using matplotlib 1.1, now updated to 1.1.1, but that did not affect it. Also, I am not using the built-in LaTeX typesetting.


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to