When using the font-weight property values in Matplotlib I got the impression the weights were all extremely bold. I looked up the font-weight property in the W3C CSS spec and it appears the legal range is 100-900, and 400 is supposed to look "Regular", 700 "Bold".
When using a plot with a Text object, everything above 100 seems to be bold though, as can be seen in the attached image.
Sure, I am using Python 3.4.1 with matplotlib 1.4.3 on OSX 10.10.5 (in a virtualenv). Although I generated the test files in IPython Notebook, I originally encountered the problem in a separate Python program.
It seems to work fine for me. Have you tried deleting your matplotlib font cache (in ~/.matplotlib). Matplotlib won't pick up newly installed fonts otherwise.
There was only one file in that directory (fontList.py3k.cache) which I deleted, but the results appear the same.
As I was getting worried that there might be a problem with the installed fonts I opened the /Library/Fonts map using Finder and they same to be available:
Also FontConfig seems to have access to these fonts:
fc-list |grep -i roboto
/Library/Fonts/Roboto-Black.ttf: Roboto,Roboto Black:style=Black,Regular
/Library/Fonts/Roboto-ThinItalic.ttf: Roboto,Roboto Thin:style=Thin Italic,Italic
/Library/Fonts/Roboto-Thin.ttf: Roboto,Roboto Thin:style=Thin,Regular
/Library/Fonts/Roboto-MediumItalic.ttf: Roboto,Roboto Medium:style=Medium Italic,Italic
/Library/Fonts/Roboto-LightItalic.ttf: Roboto,Roboto Light:style=Light Italic,Italic
/Library/Fonts/Roboto-Bold.ttf: Roboto:style=Bold
/Library/Fonts/Roboto-BoldItalic.ttf: Roboto:style=Bold Italic
/Library/Fonts/Roboto-Medium.ttf: Roboto,Roboto Medium:style=Medium,Regular
/Library/Fonts/Roboto-BlackItalic.ttf: Roboto,Roboto Black:style=Black Italic,Italic
/Library/Fonts/Roboto-Italic.ttf: Roboto:style=Italic
/Library/Fonts/Roboto-Regular.ttf: Roboto:style=Regular
/Library/Fonts/Roboto-Light.ttf: Roboto,Roboto Light:style=Light,Regular
Hmm... Can you put verbose.level : debug in ~/.matplotlib/matplotlibrc and run your script again, sending the output here? There is definitely something environmental about your system that's preventing it from seeing/using all the fonts.
I tried, but for some reason setting it in matplotlibrc didn't give any output (and I did set the fileo to filename, file object, and sys.stdout/sys.stderr). I tried with:
And got just once a file with some output, but not very useful output. It was huge (due to debug-annoying I guess, but level 'debug' gave me no output at all), so I used filter the data a bit:
ic@MacBookPro ~ $ ls -l ~/.fontconfig/
total 2728
-rw-r--r-- 1 ic staff 266128 Nov 5 2014 0f0db7876307790c19e1f91eb9095080-x86.cache-3
-rw-r--r-- 1 ic staff 265432 Nov 5 2014 1487dd4aecf3164c4a11193169052443-x86.cache-3
-rw-r--r-- 1 ic staff 80 Nov 5 2014 49aa604a5ac92994756d3008e408245c-x86.cache-3
-rw-r--r-- 1 ic staff 72 Jun 26 2014 530698deb7878507edc87921bdb300f1-x86.cache-3
-rw-r--r-- 1 ic staff 144 Nov 12 2014 558352270fb122ca08359d23b5a778d4-x86.cache-3
-rw-r--r-- 1 ic staff 96 Nov 5 2014 5dc9fcf026e07a49c5f91c19054b9930-x86.cache-3
-rw-r--r-- 1 ic staff 64616 Nov 5 2014 79652363633577d7d713baab7f54ad8c-x86.cache-3
-rw-r--r-- 1 ic staff 703568 Nov 5 2014 84c0f976e30e948e99073af70f4ae876-x86.cache-3
-rw-r--r-- 1 ic staff 200 Jan 23 2014 CACHEDIR.TAG
-rw-r--r-- 1 ic staff 19560 Nov 5 2014 a1a78d9c18cd095d3829c724810e6ffb-x86.cache-3
-rw-r--r-- 1 ic staff 18760 Nov 5 2014 ba022efc551c75e21c690774bbcf5304-x86.cache-3
-rw-r--r-- 1 ic staff 18576 Nov 5 2014 bc06c1eea3e636f72101cafc3fb39508-x86.cache-3
-rw-r--r-- 1 ic staff 456 Jun 26 2014 c5f5d66d15c24edc3e863c27139db87e-x86.cache-3
-rw-r--r-- 1 ic staff 80 Nov 5 2014 f0f76015ef54ea3f0895465d59f141ef-x86.cache-3
-rw-r--r-- 1 ic staff 88 Nov 5 2014 f22309b238134d3cca63435f528976cd-x86.cache-3
So, I tried clearing the cache with font-config:
fc-cache -f
That didn't change anything.
fc-cache -r
This didn't change anything either (the dates in the directories shown above remained the same).
So, then "rm" did get rid of the cached files, after which I used fc-cache -f again to regenerate the caches.
Unfortunately, the fonts still look the same. And grepping to the new struss output, still shows only the same files being accessed, and so the roboto-thin and roboto-light still being ignored/not found.
I also had a look at the configuration files of font-config
After you cleared the fontconfig cache, did you also clear matplotlib's cache again?
I'd still like to see the long debug-annoying output, even though it is long. It does have lines in there about how the font lookup is performed (which strace/dtrace obviously won't give you).
Closing for lack of activity, because @mdboom could not reproduce the issue, and I cannot either.
Feel free to request a reopen if you have additional information.
@mdboom The documentation for the set_weigth method of FontProperties class states that:
Set the font weight. May be either a numeric value in the range 0-1000 or one of 'ultralight', 'light', 'normal', 'regular', 'book', 'medium', 'roman', 'semibold', 'demibold', 'demi', 'bold', 'heavy', 'extra bold', 'black'
If a numeric value is provided, how do we correspond this numeric with the finite font weight options? I can not seem to find the actual code implementing this correspondence.
Activity
takis commented on Oct 15, 2015
The expected appearance can be seen here:

https://www.google.com/fonts/specimen/Roboto
mdboom commented on Oct 15, 2015
Can you provide the code you used to produce the plot in the original post?
Also, what version of matplotlib are you using, which platform, and what version of freetype?
I can't seem to reproduce the problem, but it may just be the particular method I'm using.
takis commented on Oct 15, 2015
Sure, I am using Python 3.4.1 with matplotlib 1.4.3 on OSX 10.10.5 (in a virtualenv). Although I generated the test files in IPython Notebook, I originally encountered the problem in a separate Python program.
Here's the example code:
takis commented on Oct 15, 2015
Oh, and the version of freetype according to freetype-config:
mdboom commented on Oct 15, 2015
It seems to work fine for me. Have you tried deleting your matplotlib font cache (in ~/.matplotlib). Matplotlib won't pick up newly installed fonts otherwise.
takis commented on Oct 16, 2015
There was only one file in that directory (fontList.py3k.cache) which I deleted, but the results appear the same.
As I was getting worried that there might be a problem with the installed fonts I opened the /Library/Fonts map using Finder and they same to be available:

Also FontConfig seems to have access to these fonts:
fc-list |grep -i roboto
/Library/Fonts/Roboto-Black.ttf: Roboto,Roboto Black:style=Black,Regular
/Library/Fonts/Roboto-ThinItalic.ttf: Roboto,Roboto Thin:style=Thin Italic,Italic
/Library/Fonts/Roboto-Thin.ttf: Roboto,Roboto Thin:style=Thin,Regular
/Library/Fonts/Roboto-MediumItalic.ttf: Roboto,Roboto Medium:style=Medium Italic,Italic
/Library/Fonts/Roboto-LightItalic.ttf: Roboto,Roboto Light:style=Light Italic,Italic
/Library/Fonts/Roboto-Bold.ttf: Roboto:style=Bold
/Library/Fonts/Roboto-BoldItalic.ttf: Roboto:style=Bold Italic
/Library/Fonts/Roboto-Medium.ttf: Roboto,Roboto Medium:style=Medium,Regular
/Library/Fonts/Roboto-BlackItalic.ttf: Roboto,Roboto Black:style=Black Italic,Italic
/Library/Fonts/Roboto-Italic.ttf: Roboto:style=Italic
/Library/Fonts/Roboto-Regular.ttf: Roboto:style=Regular
/Library/Fonts/Roboto-Light.ttf: Roboto,Roboto Light:style=Light,Regular
mdboom commented on Oct 16, 2015
Hmm... Can you put verbose.level : debug in ~/.matplotlib/matplotlibrc and run your script again, sending the output here? There is definitely something environmental about your system that's preventing it from seeing/using all the fonts.
takis commented on Oct 17, 2015
I tried, but for some reason setting it in matplotlibrc didn't give any output (and I did set the fileo to filename, file object, and sys.stdout/sys.stderr). I tried with:
And with:
And got just once a file with some output, but not very useful output. It was huge (due to debug-annoying I guess, but level 'debug' gave me no output at all), so I used filter the data a bit:
So, in the end, I gave up on set_level and fileo, and tried the Linux strace equivalent:
sudo dtruss -f -t open python ic-20151017-matplotlib_font_weight.py 2> mpl-log.txt grep ttf mpl-log.txt |sort -u 20907/0xc3cdc: open("/Library/Fonts/Courier New.ttf\0", 0x0, 0x1B6) = 28 0 20907/0xc3cdc: open("/Library/Fonts/Roboto-Black.ttf\0", 0x0, 0x1B6) = 16 0 20907/0xc3cdc: open("/Library/Fonts/Roboto-Bold.ttf\0", 0x0, 0x1B6) = 16 0 20907/0xc3cdc: open("/Library/Fonts/Roboto-Medium.ttf\0", 0x0, 0x1B6) = 16 0 20907/0xc3cdc: open("/Library/Fonts/Verdana.ttf\0", 0x0, 0x1B6) = 15 0But these are the fonts available:
So, I noticed that struss also showed these directories to be accessed, and I figured it might be a stale cache issue.
And indeed the dates were really old:
So, I tried clearing the cache with font-config:
That didn't change anything.
This didn't change anything either (the dates in the directories shown above remained the same).
So, then "rm" did get rid of the cached files, after which I used fc-cache -f again to regenerate the caches.
Unfortunately, the fonts still look the same. And grepping to the new struss output, still shows only the same files being accessed, and so the roboto-thin and roboto-light still being ignored/not found.
I also had a look at the configuration files of font-config
But, I isn't mentioned in these files. I am not sure if this might be the problem, so I am looking at this now.
mdboom commented on Oct 19, 2015
After you cleared the fontconfig cache, did you also clear matplotlib's cache again?
I'd still like to see the long debug-annoying output, even though it is long. It does have lines in there about how the font lookup is performed (which strace/dtrace obviously won't give you).
anntzer commented on Jan 14, 2018
Closing for lack of activity, because @mdboom could not reproduce the issue, and I cannot either.
Feel free to request a reopen if you have additional information.
jdhao commented on Jan 8, 2019
@mdboom The documentation for the set_weigth method of FontProperties class states that:
If a numeric value is provided, how do we correspond this numeric with the finite font weight options? I can not seem to find the actual code implementing this correspondence.
anntzer commented on Jan 8, 2019
These are (... supposed to be) css font weights per https://developer.mozilla.org/en-US/docs/Web/CSS/font-weight#Values.
jdhao commented on Jan 8, 2019
Thanks, that resolves my questions.