# Problems with, LaTeX symbols, axes rescaling

Yesterday I compiled Matplotlib from SVN, and installed it to run on top of the dependencies that I have installed from the SciPy Superpack for OS X from Chris Fonnesbeck. Nearly everything seems to be working fine. However, there are a couple of glitches, and I can’t tell whether it’s because of something being out of sync between all my installed bits, or whether it’s just the fact that I’m using the SVN code.

The first thing I noticed is that all of the LaTeX symbols I have in my plots are now messed up. I could see this being a font issue… does anyone know how/where Matplotlib gets pointed at the LaTeX fonts? And how I would check to see where it’s looking, or whether it’s not finding what it’s looking for? I’m not getting any errors - my greek letters just cease to be greek, and various text decorations (like \bar{D}) come out as other things altogether (like D, only with an Angstrom symbol over it…).

The second thing is that in a figure in which I’m using twinx() to create a separate y-axis using the same x-axis, I no longer seem to be able to control the limits of the new axes. They just automatically re-scale to fit whatever data is being plotted, regardless of whether I use ax.set_ylim().

Third, and this was a problem before I did the re-compile, and it remains so, often (but not always) my figures refuse to draw completely, until I’ve re-sized the window in which they’re being displayed. This happens even when I do a figure.show() at the end of the script. Some of the lines will draw, but not all of them. Is this a familiar problem?

Thanks for any suggestions…

Zane

···

Zane Selvans

Amateur Earthling

zane@…1923…

303/815-6866

http://zaneselvans.org

PGP Key: 55E0815F

Zane Selvans wrote:

Yesterday I compiled Matplotlib from SVN, and installed it to run on top

[...]

The second thing is that in a figure in which I'm using twinx() to create a separate y-axis using the same x-axis, I no longer seem to be able to control the limits of the new axes. They just automatically re-scale to fit whatever data is being plotted, regardless of whether I use ax.set_ylim().

Formerly, autoscaling was not supported by shared axes, which would have included twinx. Now autoscaling is supported. I suspect this is the difference you are seeing. The solution is to turn off autoscaling with the ax.set_autoscale_on method, or to call ax.set_ylim after you have plotted your lines.

Eric

whether it's just the fact that I'm using the SVN code.
The first thing I noticed is that all of the LaTeX symbols I have in my
plots are now messed up. I could see this being a font issue... does anyone
know how/where Matplotlib gets pointed at the LaTeX fonts? And how I would
check to see where it's looking, or whether it's not finding what it's
looking for? I'm not getting any errors - my greek letters just cease to be
greek, and various text decorations (like \bar{D}) come out as other things
altogether (like D, only with an Angstrom symbol over it...).

I suggest completely wiping your .matplotlib directory (saving only
your matplotlibrc if you have customized it). matplotlib caches a
fair amount of font and latex rendering stuff. I had a similar
problem on an upgrade with mathtext. We are not sure why it is
happening yet, but it will probably go away if you rm -rf
~/.matplotlib. Also, wipe your site-packages/matplotlib dir before
installing. See

To get more verbose information about what mpl is doing behind the
scense, run with

> python myscript.py --verbose-debug

You can use --verbose-helpful for less output.

I think it might be a good idea for us to start using a versioned dir
structure for the cached data...

JDH

···

On Mon, Nov 24, 2008 at 6:23 PM, Zane Selvans <zane@...1923...> wrote:

Thanks, this fixed it!

Though, futzing with the LaTeX settings in the new matplotlibrc it appears that something about how/when it chooses when to format as tex has changed. If text.usetex is True, text in my labels and titles that is enclosed within $$'s gets typeset as tex, but apparently all of the xtick labels get set as mathtext - they’re in the light/thin and slightly more difficult to read LaTeX font, and in my Basemap figures, the NSEW modifiers on the text objects indicating lat/lon direction are all italicised, as they would be were they enclosed in$$'s. I don’t seem to be able to get the relatively bold, sans-serif tick labels, while still preserving the ability to typeset math in my labels and titles…

(An aside: how does one go about decorating the Text objects that label the ticks? I frequently have an axis whose units are degrees, and I’d rather just be able to append a $^\circ$ on the end of the text for the ticks, rather than have to say in the axis label [degrees].)

If I set text.markup to ‘tex’, instead of ‘plain’ I get a complaint about it being invalid, with a pointer to a URL that no longer exists to obtain a new matplotlibrc:

Bad key “text.markup” on line 162 in /Users/zane/.matplotlib/matplotlibrc.

You probably need to get an updated matplotlibrc file from http://matplotlib.sf.net/matplotlibrc or from the matplotlib source distribution

Thanks again!

Zane

···

On Nov 24, 2008, at 5:23 PM, John Hunter wrote:

The first thing I noticed is that all of the LaTeX symbols I have in my
plots are now messed up. I could see this being a font issue… does anyone

I suggest completely wiping your .matplotlib directory (saving only

your matplotlibrc if you have customized it). matplotlib caches a

Zane Selvans

Amateur Earthling

zane@…1923…

303/815-6866

http://zaneselvans.org

PGP Key: 55E0815F

The first thing I noticed is that all of the LaTeX symbols I have in my

plots are now messed up. I could see this being a font issue... does anyone

I suggest completely wiping your .matplotlib directory (saving only

your matplotlibrc if you have customized it). matplotlib caches a

Thanks, this fixed it!
Though, futzing with the LaTeX settings in the new matplotlibrc it appears
that something about how/when it chooses when to format as tex has changed.
If text.usetex is True, text in my labels and titles that is enclosed
within $$'s gets typeset as tex, but apparently *all* of the xtick labels get set as mathtext - they're in the light/thin and slightly more difficult to read LaTeX font, and in my Basemap figures, the NSEW modifiers on the text objects indicating lat/lon direction are all italicised, as they would be were they enclosed in$$'s. I don't seem to be able to get the
relatively bold, sans-serif tick labels, while still preserving the ability
to typeset math in my labels and titles...

We have two modes to render latex -- one is native TeX layout and uses
latex and dvipng, and is superior if you need all of TeX's
capabilities (eg an eqnarray), but the fonts are suboptimal. The
other is mathtext, which will cover 98% of most users' math needs,
does not require a latex install because it is pure mpl, and uses
nicer fonts . The docs are here:

I strongly encourage using mathtext over usetex, unless you need some
of the hairy stuff from TeX.

(An aside: how does one go about decorating the Text objects that label the
ticks? I frequently have an axis whose units are degrees, and I'd rather
just be able to append a $^\circ$ on the end of the text for the ticks,
rather than have to say in the axis label [degrees].)

Use a custom formatter. I'm freestyling here, so check the examples

import matplotlib.ticker as ticker
formatter = ticker.FormatStrFormatter(r'$%1.2f^\circ$')
ax.xaxis.set_major_formatter(formatter)

The API docs for the tick formatting and locating are here

And code examples matching "formatter" are here

If I set text.markup to 'tex', instead of 'plain' I get a complaint about it
being invalid, with a pointer to a URL that no longer exists to obtain a new
matplotlibrc:
Bad key "text.markup" on line 162 in /Users/zane/.matplotlib/matplotlibrc.
You probably need to get an updated matplotlibrc file
from http://matplotlib.sf.net/matplotlibrc or from the matplotlib
source distribution

I've updated the code in svn to point to the new location

JDH

···

On Mon, Nov 24, 2008 at 8:37 PM, Zane Selvans <zane@...1923...> wrote:

On Nov 24, 2008, at 5:23 PM, John Hunter wrote:

We have two modes to render latex – one is native TeX layout and uses
latex and dvipng, and is superior if you need all of TeX’s
capabilities (eg an eqnarray), but the fonts are suboptimal. The
other is mathtext, which will cover 98% of most users’ math needs,
does not require a latex install because it is pure mpl, and uses
nicer fonts .

Well, if I turn off usetex, then the LaTeX symbols don’t get rendered correctly. It’s obviously trying to do something other than just write out the plain text, but it’s not doing the right thing. I quit out of matplotlib, and re-purged all the cached stuff from my .matplotlib directory, and it’s still failing. From the docs, it sounds like mathtext is just the default way for Text objects to get rendered. It fails the same way irrespective of whether I use a raw string, or a double-quoted string:

fit_ax.set_ylabel(r’$\delta_{rms}$ [degrees]’)

fit_ax.set_ylabel("$\delta_{rms}$ [degrees]")

both give a capital ‘C’ with a subscript ‘rms’

$\bar{D}$ results in a capital D with a little circle over it.

$20^\circ$ yields 20 raised to the little tiny ‘e’ power.

Even if I wipe my site-packages/matplotlib* directory and egg-info, make clean, and recompile and install matplotlib from the SVN source, I still get the same problem. I don’t know if it means anything, but I note that the mpl-data/fonts directory in SVN has 282 sub-entries, and the mpl-data/fonts directory that’s getting installed in my site-packages only has 99 sub-entries. But maybe they aren’t supposed to be the same? Dunno.

So for now I can only get my math symbols to render with text.usetext turned on.

I’ll read up on the text formatters. Thanks for all your help!

Zane

···

Zane Selvans

Amateur Earthling

zane@…1923…

303/815-6866

http://zaneselvans.org

PGP Key: 55E0815F

I'm seeing this here, too. Something must have been messed up recently in SVN. I'm looking into it.

Mike

Zane Selvans wrote:

We have two modes to render latex -- one is native TeX layout and uses
latex and dvipng, and is superior if you need all of TeX's
capabilities (eg an eqnarray), but the fonts are suboptimal. The
other is mathtext, which will cover 98% of most users' math needs,
does not require a latex install because it is pure mpl, and uses
nicer fonts .

Well, if I turn off usetex, then the LaTeX symbols don't get rendered correctly. It's obviously trying to do something other than just write out the plain text, but it's not doing the right thing. I quit out of matplotlib, and re-purged all the cached stuff from my .matplotlib directory, and it's still failing. From the docs, it sounds like mathtext is just the default way for Text objects to get rendered. It fails the same way irrespective of whether I use a raw string, or a double-quoted string:

fit_ax.set_ylabel(r'$\delta_{rms}$ [degrees]')
fit_ax.set_ylabel("$\delta_{rms}$ [degrees]")

both give a capital 'C' with a subscript 'rms'

$\bar{D}$ results in a capital D with a little circle over it.

$20^\circ$ yields 20 raised to the little tiny 'e' power.
Even if I wipe my site-packages/matplotlib* directory and egg-info, make clean, and recompile and install matplotlib from the SVN source, I still get the same problem. I don't know if it means anything, but I note that the mpl-data/fonts directory in SVN has 282 sub-entries, and the mpl-data/fonts directory that's getting installed in my site-packages only has 99 sub-entries. But maybe they aren't supposed to be the same? Dunno.
So for now I can only get my math symbols to render with text.usetext turned on.

I'm seeing

···

--
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA

I introduced this bug trying to fix the Cairo backend on Nov 12. (r6400). It should now be fixed in SVN r6446. You will need to remove ~/.matplotlibrc/fontList.cache for the fix to take effect.

Mike

Michael Droettboom wrote:

···

I'm seeing this here, too. Something must have been messed up recently in SVN. I'm looking into it.

Mike

Zane Selvans wrote:

We have two modes to render latex -- one is native TeX layout and uses
latex and dvipng, and is superior if you need all of TeX's
capabilities (eg an eqnarray), but the fonts are suboptimal. The
other is mathtext, which will cover 98% of most users' math needs,
does not require a latex install because it is pure mpl, and uses
nicer fonts .

Well, if I turn off usetex, then the LaTeX symbols don't get rendered correctly. It's obviously trying to do something other than just write out the plain text, but it's not doing the right thing. I quit out of matplotlib, and re-purged all the cached stuff from my .matplotlib directory, and it's still failing. From the docs, it sounds like mathtext is just the default way for Text objects to get rendered. It fails the same way irrespective of whether I use a raw string, or a double-quoted string:

fit_ax.set_ylabel(r'$\delta_{rms}$ [degrees]')
fit_ax.set_ylabel("$\delta_{rms}$ [degrees]")

both give a capital 'C' with a subscript 'rms'

$\bar{D}$ results in a capital D with a little circle over it.

$20^\circ$ yields 20 raised to the little tiny 'e' power.
Even if I wipe my site-packages/matplotlib* directory and egg-info, make clean, and recompile and install matplotlib from the SVN source, I still get the same problem. I don't know if it means anything, but I note that the mpl-data/fonts directory in SVN has 282 sub-entries, and the mpl-data/fonts directory that's getting installed in my site-packages only has 99 sub-entries. But maybe they aren't supposed to be the same? Dunno.
So for now I can only get my math symbols to render with text.usetext turned on.

I'm seeing

--
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA