MPL uses character not defined by cmr10?

Sorry, I meant to reply to the list.

After clearing the fontlist cache, I was able to get this fix working.

Just to summarize:

  • download unicode version of computer modern fonts (http://sourceforge.net/projects/cm-unicode/files/)—make sure to get the ttf version

  • clear out the fontlist cache (rm ~/.matplotlib/fontList.cache)

  • add the following to ~/matplotlib/matplotlibrc:

font.family: serif

font.serif: CMU Serif

  • alternatively, you could leave the default as sans serif and use the computer modern sans serif (unicode version):

font.sans-serif: CMU Sans Serif

These changes produce plots where the size of normal text matches that of mathtext.

Thanks for you help, Mike!

-Tony

···

On Apr 29, 2010, at 10:43 PM, Tony S Yu wrote:

On Apr 29, 2010, at 6:09 PM, Michael Droettboom wrote:

Those Computer Modern fonts (specifically the Bakoma distribution of
them that matplotlib includes) use a custom character set mapping where
many of the characters are in completely arbitrary locations. For
regular text, matplotlib expects a regular Unicode font (particularly
to get the minus sign). Since cmr10 doesn’t have a standard encoding,
it just won’t work.

Hey Mike,

Thanks for your reply. That makes sense.

An alternative work around (I presume) would be to install the computer modern unicode fonts (I made sure to install the ttf version). However, I’m having trouble getting MPL to find the fonts.

The installed font is listed when calling mpl.font_manager.OSXInstalledFonts(), but it’s not found when calling mpl.font_manager.findfont (with various names that would make sense: cmunrm, CMU Serif, etc.)

Any ideas on what I’m doing wrong?

Those Computer Modern fonts (specifically the Bakoma distribution of
them that matplotlib includes) use a custom character set mapping where
many of the characters are in completely arbitrary locations. For
regular text, matplotlib expects a regular Unicode font (particularly
to get the minus sign). Since cmr10 doesn’t have a standard encoding,
it just won’t work.

Hey Mike,

Thanks for your reply. That makes sense.

An alternative work around (I presume) would be to install the computer modern unicode fonts (I made sure to install the ttf version). However, I’m having trouble getting MPL to find the fonts.

The installed font is listed when calling mpl.font_manager.OSXInstalledFonts(), but it’s not found when calling mpl.font_manager.findfont (with various names that would make sense: cmunrm, CMU Serif, etc.)

Any ideas on what I’m doing wrong?

Sorry, I meant to reply to the list.

After clearing the fontlist cache, I was able to get this fix working.

Just to summarize:

  • clear out the fontlist cache (rm ~/.matplotlib/fontList.cache)
  • add the following to ~/matplotlib/matplotlibrc:

font.family: serif

font.serif: CMU Serif

  • alternatively, you could leave the default as sans serif and use the computer modern sans serif (unicode version):

font.sans-serif: CMU Sans Serif

These changes produce plots where the size of normal text matches that of mathtext.

Thanks for you help, Mike!

-Tony

Umm, … last email on this topic, I promise.

Is there any reason the font family rc parameter is case sensitive, while the findfont input is case insensitive? In other words, replacing

font.serif: CMU Serif

with

font.serif: cmu serif

does not work. On the other hand, both of the following work:

mpl.font_manager.findfont(‘cmu serif’)

mpl.font_manager.findfont(‘CMU Serif’)

This caused me problems when debugging my earlier font troubles.

Best,

-Tony

···

On Apr 29, 2010, at 11:51 PM, Tony S Yu wrote:

On Apr 29, 2010, at 10:43 PM, Tony S Yu wrote:

On Apr 29, 2010, at 6:09 PM, Michael Droettboom wrote:

I wasn't aware of these fonts -- we may want to consider distributing them with matplotlib instead (assuming the licensing makes sense) as it would greatly simplify the mathtext code. Of course, that's a project I may not have time for right now.

I'll look into the case-sensitivity issue -- I'm not sure why that is the case.

Mike

Tony S Yu wrote:

···

On Apr 29, 2010, at 10:43 PM, Tony S Yu wrote:

On Apr 29, 2010, at 6:09 PM, Michael Droettboom wrote:

Those Computer Modern fonts (specifically the Bakoma distribution of them that matplotlib includes) use a custom character set mapping where many of the characters are in completely arbitrary locations. For regular text, matplotlib expects a regular Unicode font (particularly to get the minus sign). Since cmr10 doesn't have a standard encoding, it just won't work.

Hey Mike,

Thanks for your reply. That makes sense.

An alternative work around (I presume) would be to install the computer modern unicode fonts <http://sourceforge.net/projects/cm-unicode/files/> (I made sure to install the ttf version). However, I'm having trouble getting MPL to find the fonts.

The installed font is listed when calling `mpl.font_manager.OSXInstalledFonts()`, but it's not found when calling `mpl.font_manager.findfont` (with various names that would make sense: cmunrm, CMU Serif, etc.)

Any ideas on what I'm doing wrong?

Sorry, I meant to reply to the list.

After clearing the fontlist cache, I was able to get this fix working.

Just to summarize:

* download unicode version of computer modern fonts (http://sourceforge.net/projects/cm-unicode/files/)—make sure to get the ttf version

* clear out the fontlist cache (rm ~/.matplotlib/fontList.cache)

* add the following to ~/matplotlib/matplotlibrc:

    font.family: serif
    font.serif: CMU Serif

* alternatively, you could leave the default as sans serif and use the computer modern sans serif (unicode version):

    font.sans-serif: CMU Sans Serif

These changes produce plots where the size of normal text matches that of mathtext.

Thanks for you help, Mike!

-Tony

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

Michael Droettboom wrote:

I wasn't aware of these fonts -- we may want to consider distributing them with matplotlib instead (assuming the licensing makes sense) as it would greatly simplify the mathtext code. Of course, that's a project I may not have time for right now.
  

On further looking into these fonts, it seems they're not appropriate at the moment. They are missing a number of math-related symbols (such as infinity, for example). They are worth keeping an eye on, because they have a much better and more open framework for being built vs. the Bakoma fonts which are essentially "closed-source" though free for redistribution. (i.e. it makes it a lot harder to fix problems in them). Given the time, I may look into what it would take to start adding these new symbols.

I'll look into the case-sensitivity issue -- I'm not sure why that is the case.
  

This has now been fixed in SVN.

Mike

···

Mike

Tony S Yu wrote:
  

On Apr 29, 2010, at 10:43 PM, Tony S Yu wrote:

On Apr 29, 2010, at 6:09 PM, Michael Droettboom wrote:

Those Computer Modern fonts (specifically the Bakoma distribution of them that matplotlib includes) use a custom character set mapping where many of the characters are in completely arbitrary locations. For regular text, matplotlib expects a regular Unicode font (particularly to get the minus sign). Since cmr10 doesn't have a standard encoding, it just won't work.
        

Hey Mike,

Thanks for your reply. That makes sense.

An alternative work around (I presume) would be to install the computer modern unicode fonts <http://sourceforge.net/projects/cm-unicode/files/> (I made sure to install the ttf version). However, I'm having trouble getting MPL to find the fonts.

The installed font is listed when calling `mpl.font_manager.OSXInstalledFonts()`, but it's not found when calling `mpl.font_manager.findfont` (with various names that would make sense: cmunrm, CMU Serif, etc.)

Any ideas on what I'm doing wrong?
      

Sorry, I meant to reply to the list.

After clearing the fontlist cache, I was able to get this fix working.

Just to summarize:

* download unicode version of computer modern fonts (http://sourceforge.net/projects/cm-unicode/files/)—make sure to get the ttf version

* clear out the fontlist cache (rm ~/.matplotlib/fontList.cache)

* add the following to ~/matplotlib/matplotlibrc:

    font.family: serif
    font.serif: CMU Serif

* alternatively, you could leave the default as sans serif and use the computer modern sans serif (unicode version):

    font.sans-serif: CMU Sans Serif

These changes produce plots where the size of normal text matches that of mathtext.

Thanks for you help, Mike!

-Tony

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