SourceForge logo
SourceForge logo
Menu

matplotlib-users

From: Tony S Yu <ts...@gm...> - 2010年04月29日 19:33:38
There was a recent thread about the font sizes not matching up between regular text and math text. I decided I'd try to get matching font sizes by using computer modern as the default font, so I added the following to my matplotlibrc file:
font.family: serif
font.serif: cmr10
This fixes the font size issue, but for some reason, MPL's minus sign seems to be using a character not defined by the computer modern fonts (see y-axis in attached image).
Is there a fix for this missing character?
Best,
-Tony
P.S. I'm using the cmr10 fonts provided by MPL (confirmed by using the findfont function).
From: Michael D. <md...@st...> - 2010年04月29日 22:09:50
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.
You could get around this by overriding the default formatter to use a 
different symbol for the minus sign. See this example for an example of 
overriding the formatter:
http://matplotlib.sourceforge.net/examples/pylab_examples/major_minor_demo1.html#pylab-examples-major-minor-demo1
Mike
On 04/29/2010 03:33 PM, Tony S Yu wrote:
> There was a recent thread about the font sizes 
> <http://old.nabble.com/mathtext-is-smaller-than-regular-text-ts28374364.html> not 
> matching up between regular text and math text. I decided I'd try to 
> get matching font sizes by using computer modern as the default font, 
> so I added the following to my matplotlibrc file:
>
> font.family: serif
> font.serif: cmr10
>
> This fixes the font size issue, but for some reason, MPL's minus sign 
> seems to be using a character not defined by the computer modern fonts 
> (see y-axis in attached image).
>
> Is there a fix for this missing character?
>
> Best,
> -Tony
>
> P.S. I'm using the cmr10 fonts provided by MPL (confirmed by using the 
> findfont function).
>
>
> ------------------------------------------------------------------------------
> 
>
>
> _______________________________________________
> Matplotlib-users mailing list
> Mat...@li...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
> 
From: Tony S Yu <ts...@gm...> - 2010年04月30日 03:51:13
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?
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
From: Tony S Yu <ts...@gm...> - 2010年04月30日 03:57:46
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:
>> 
>>> 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:
> 
> * 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
> 
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
From: Michael D. <md...@st...> - 2010年04月30日 13:07:27
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
From: Michael D. <md...@st...> - 2010年04月30日 16:11:47
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
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.
Thanks for helping keep SourceForge clean.
X





Briefly describe the problem (required):
Upload screenshot of ad (required):
Select a file, or drag & drop file here.
Screenshot instructions:

Click URL instructions:
Right-click on the ad, choose "Copy Link", then paste here →
(This may not be possible with some types of ads)

More information about our ad policies

Ad destination/click URL:

AltStyle によって変換されたページ (->オリジナル) /