Hmm, no reply again. Are these emails getting through? I appreciate this was quite a long and detailed question -- maybe I should raise these sorts of things on the MPL dev list instead? I'm happy to contribute on improving the (TeX) font control, if there's interest, but for now found a workaround using the mathspec package:
mpl.rcParams["font.serif"] = ["TeX Gyre Pagella"] mpl.rcParams["pgf.preamble"] = [r"\usepackage{mathspec}", r"\defaultfontfeatures{Numbers=OldStyle}", r"\setmathsfont(Digits,Greek){TeX Gyre Pagella}"] and variations on that theme. Not wonderfully integrated, and could be improved, but it does allow the math font (used for tick labels for some reason) to be specified as completely as the text one. Cheers, Andy On 03/11/14 22:59, Andy Buckley wrote: > Hi again, > > I didn't see any on-list answer, but got an off-list suggestion to use > an rc parameter to set a LaTeX preamble. I played around a little and > thought I should report on what I found, especially since it seems that > there is room for improvement here and I'd be interested to help. > > Here are the relevant rc params that I have set: > > "font.size" : 17, > "font.family" : "serif", > "font.serif" : ["TeX Gyre Pagella"], > "pgf.rcfonts" : True, > "pgf.preamble": [r"\usepackage{amsmath,amssymb}", > r"\usepackage{fontspec}", r"\defaultfontfeatures{Numbers=OldStyle}"], > > > A couple of points to note here: > > * I'm using the PGF backend -- this ran a bit faster and produced much > smaller files than MPL rendering with TeX labels (text.usetex = True). > Also, I have data files with labels using macros like \text which MPL > MathText doesn't support, so I need to be able to include amsmath. > > * I've had to set TeX Gyre Pagella rather than Palatino, since this SE > question points out that fontspec's Palatino doesn't support small-caps > and old-style > figures:http://tex.stackexchange.com/questions/2994/fontspec-palatino-with-small-caps-and-old-style-figures > > * Although the backend uses fontspec, I have to import it explicitly in > my preamble, because the MPL import and use of fontspec happens _after_ > where the pgf.preamble key is inserted. Actually, given that I found > fontspec doesn't seem to do the right thing for most math fonts, maybe I > need to ignore the rcfonts setting and do it a bit more manually if I > want full control -- pity. > > > If I ask this configuration to output a PDF file, though, I don't get > old-style figures as intended. So I started looking at the generated TeX > source by outputting as .pgf and wrapping in a little LaTeX file like this: > > \documentclass[12pt,minimal]{standalone} > \usepackage{pgf} > \usepackage{amsmath,amssymb} > > \usepackage{fontspec} > \setmainfont[Numbers=OldStyle]{TeX Gyre Pagella} > > \begin{document} > \input{plot.pgf} > \end{document} > > I've attached the result of this with the default MPL .pgf output as > plot-mpldefault.pdf. A couple of things are notable in that plot: > > * Old-style figures are used in the legend (where math mode is not > used), but the axis tick labels are not. > > * The full-size figures on the axes are very thin weight compared to > the text axis labels -- I knew something had looked a bit wrong in the > default output! > > > Looking in the .pgf file, the reason is clear. The axis ticks are in > display math mode, like this: > > > \pgftext[x=0.987638in,y=1.778400in,right,]{{\rmfamily\fontsize{17.000000}{20.400000}\selectfont > \(\displaystyle 1.05\)}}% > ^^^^^^^^^^^^^^^^^^^^^^ > > I removed the \(\displaystyle and \) from the file and then recompiled > with and without the Numbers=OldStyle spec in the wrapper, producing the > attached plot-textoldstyle.pdf and plot-textlining.pdf figures. In both > of these the weight of the tick labels is much more balanced with the > other labels than in the default; the old-style or lining figure style > is more a matter of personal preference, but I would like to have the > option. > > > Apologies for the long email! I'd appreciate any feedback. It seems that > there are a couple of small tweaks which would greatly improve the MPL > TeX/PGF output, although they probably have side-effects of which I'm > unaware: > > * Don't put tick labels in math mode by default (i.e. unless a special > ticker is used). In our previous code, which I'm trying to reproduce in > MPL, even exponent-format tick labels were typeset as "10$^\text{exp}$" > which automatically gets the font weights and styles correct. Is the > current \(\displaystyle etc. specified by the default ticker or is it > specific to the PGF backend? > > * I checked a bit, and fontspec seems a bit ropey when it comes to > changing math fonts to match the text font; I had to > \usepackage[osf]{mathpazo} before importing fontspec to get a correctly > weighted math font. mathspec is maybe worth investigation. > > > Thanks in advance, and thanks for tolerating this plot-cosmetics > obsessiveness ;-) > > Andy > > > > On 27/10/14 14:35, Andy Buckley wrote: >> Hi, >> >> I'm using MPL to implement a new plotter for a project has so far been >> using a custom-written LaTeX+pstricks script. Despite being slow and a >> bit hacky, the output is really quite nice and I want to try and emulate >> it as closely as possible via MPL; for example: >> >> https://users.hepforge.org/~buckley/atlas-py8-shower-e/ATLAS_2012_I1094568/d03-x02-y01.pdf >> >> I more or less have this working, but would really like to be able to >> use the "old-style figures" (OSF) numerals with variable baseline (aka >> lower-case or text figures cf. >> http://en.wikipedia.org/wiki/Text_figures), which give those plots quite >> a bit of their character. >> >> Probably this will anyway be possible only with the TeX or PGF backend >> to MPL, but what would be the best way to enable OSF figures from MPL? >> If I correctly understand the backend, the rc params font.family & e.g. >> font.serif are passed to the LaTeX fontspec package -- and in the >> fontspec documentation >> http://mirror.utexas.edu/ctan/macros/latex/contrib/fontspec/fontspec.pdf >> it seems that passing the Numbers=(OldStyle) option to the \fontspec >> command (or as the arg to \addfontfeature) would be the fontspec version >> of, for example, \usepackage[osf]{mathpazo}. Is there a way to pass >> options like this to fontspec? In general this would seem a useful thing >> to be able to do, since fontspec controls far more than OSFs, but I >> couldn't find a discussion of it in the docs. >> >> Hope you can help; thanks! >> Andy >> > > -- Dr Andy Buckley, Royal Society University Research Fellow Particle Physics Expt Group, University of Glasgow / PH Dept, CERN ------------------------------------------------------------------------------ Comprehensive Server Monitoring with Site24x7. Monitor 10 servers for $9/Month. Get alerted through email, SMS, voice calls or mobile push notifications. Take corrective actions from your mobile device. http://pubads.g.doubleclick.net/gampad/clk?id=154624111&iu=/4140/ostg.clktrk _______________________________________________ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users