Using special characters

Hello.

I've been having trouble getting Unicode characters to render. I just
get a box in the title of my figure, rather than the character I need.

Here is my code:
#!/usr/bin/env python
from pylab import *
plot([1,2,3,4])
title(u"\u0251")
savefig("test.eps")
savefig("test.png")
show()

That character is LATIN SMALL LETTER ALPHA. It's used in the
International Phonetic Alphabet.

I'm on Linux and I'm using matplotlib 0.90.1-2 (debian package
version). I have a few TTF fonts in my system that contain that
glyph. One is 'Arial Unicode MS', which I copied from my windows
machine.

As you can see, I will need to generate an EPS that renders the
character... That EPS file will be imported into MS Word on a Windows
PC and printed.

I will happily use any solution that allows me to use that character
in the final product... :slight_smile: It doesn't have to be unicode..

I believe that my fonts are configured correctly on this Linux
system--I can use the Arial Unicode MS font in Open Office. However,
I'm not sure that MPL is finding them.

When I point the TTFPATH environment variable a directory that only
contains ARIALUNI.TTF, I get gibberish for all characters in my
figure.

When I use ~/.matplotlib/matplotlibrc to list Arial Unicode MS as the
only font in the san-serif family, I don't observe any change in the
text in the figure.

...I did successfully instantiate an FT2FONT object out of my
ARIALUNI.TTF file, but, I didn't know what to do with it at that
point.

Help?

Cheers,
--Dave Loyall
Omaha, Nebraska, USA

We can first try to track down whether the Arial MS Unicode font is getting picked up. In your matplotlibrc, can you add:

   verbose: debug-annoying

and send the output of your plot to the list? You'll see where it looks up the font and whether that lookup failed or not.

There have been a number of Unicode-related fixes in SVN since the 0.90.1 release -- though most were in the PDF backend, not PS. One thing to try (don't know offhand whether it's working better or not) may be to use the Cairo backend to generate the PS and then use ps2epsi to get an EPS.

Cheers,
Mike

David Loyall wrote:

···

Hello.

I've been having trouble getting Unicode characters to render. I just
get a box in the title of my figure, rather than the character I need.

Here is my code:
#!/usr/bin/env python
from pylab import *
plot([1,2,3,4])
title(u"\u0251")
savefig("test.eps")
savefig("test.png")
show()

That character is LATIN SMALL LETTER ALPHA. It's used in the
International Phonetic Alphabet.

I'm on Linux and I'm using matplotlib 0.90.1-2 (debian package
version). I have a few TTF fonts in my system that contain that
glyph. One is 'Arial Unicode MS', which I copied from my windows
machine.

As you can see, I will need to generate an EPS that renders the
character... That EPS file will be imported into MS Word on a Windows
PC and printed.

I will happily use any solution that allows me to use that character
in the final product... :slight_smile: It doesn't have to be unicode..

I believe that my fonts are configured correctly on this Linux
system--I can use the Arial Unicode MS font in Open Office. However,
I'm not sure that MPL is finding them.

When I point the TTFPATH environment variable a directory that only
contains ARIALUNI.TTF, I get gibberish for all characters in my
figure.

When I use ~/.matplotlib/matplotlibrc to list Arial Unicode MS as the
only font in the san-serif family, I don't observe any change in the
text in the figure.

...I did successfully instantiate an FT2FONT object out of my
ARIALUNI.TTF file, but, I didn't know what to do with it at that
point.

Help?

Cheers,
--Dave Loyall
Omaha, Nebraska, USA

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

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

Michael,

Thank you. Interesting results:

With verbose.level set to debug-annoying, these lines look significant:
       findfont failed Arial Unicode MS, normal, normal 500, normal, 14.0
Could not match Arial Unicode MS, normal, normal. Returning
/usr/share/matplotlib/mpl-data/fonts/ttf/cmex10.ttf

Well, I played around with this a little more and found the problem!
The font.weight of 'medium' (500) is what could not be found. When I
switched font.weight to 'normal' (400) in matplotlibrc, it worked and
the graph was rendered with the correct glyph. (This worked for the
DejaVu Sans font, still no luck with Arial Unicode MS, but, that's
fine.)

So, problem solved, thanks again! :slight_smile:

Here's something I noticed: When I copied ARIALUNI.TTF into
/usr/share/matplotlib/mpl-data/fonts/ttf/ and ran the test plot, all
the characters are gibberish. Actually, they are glyphs, but, the
wrong ones. The same thing happens if I copy Thyromanes .ttf files
into that directory, or if I put those files in the $TTFPATH
directory. In fact, it also happens if I copy andalemo.ttf, and that
font doesn't include extra unicode characters.

So, I'll paste the entire debug-annoying output that occurred when I
was getting the gibberish text on the plot at the end of this email.
As you can see, I set the font to a nonsense string to illustrate that
the problem occurs even if the extra font in the directory isn't being
requested. Also, I made sure that the extra font wasn't duplicated
anywhere else in the search path.

Cheers,
--Dave Loyall

loaded rc file /home/hobbes/.matplotlib/matplotlibrc
matplotlib version 0.90.1
verbose.level debug-annoying
interactive is False
units is False
platform is linux2
loaded modules: ['_bisect', 'distutils', 'pylab', 'datetime',
'matplotlib.tempfile', 'distutils.sysconfig', 'pytz.datetime',
'pytz.cStringIO', 'struct', 'tempfile', 'imp', 'pytz.os', 'zipimport',
'string', 'encodings.utf_8', 'matplotlib.__future__', 'pytz.tzinfo',
'distutils.re', 'bisect', 'signal', 'random', 'token',
'matplotlib.pytz', 'dis', 'pytz.tzfile', 'cStringIO', 'locale',
'encodings', 'dateutil', 'matplotlib.warnings', 'pytz.pytz',
'matplotlib.sys', 're', 'math', 'fcntl', 'UserDict', 'inspect',
'distutils.os', 'matplotlib', 'codecs', 'md5', '_locale',
'matplotlib.os', 'thread', 'sre', 'itertools', 'opcode',
'distutils.sys', 'os', '__future__', '_sre', '__builtin__',
'matplotlib.re', 'distutils.string', 'matplotlib.datetime',
'posixpath', 'errno', 'binascii', 'sre_constants', 'matplotlib.md5',
'types', 'pytz.sys', 'tokenize', '_codecs', 'pytz', 'copy',
'matplotlib.dateutil', 'posix', 'encodings.aliases', 'exceptions',
'sre_parse', 'pytz.bisect', 'copy_reg', 'sre_compile', '_random',
'pytz.struct', 'site', '__main__', 'shutil', 'strop',
'encodings.codecs', 'gettext', 'encodings.exceptions', 'pytz.sets',
'stat', 'warnings', 'encodings.types', 'sys', 'os.path',
'pytz.gettext', 'matplotlib.distutils', 'distutils.errors',
'linecache', 'matplotlib.shutil', 'sets']
numerix numpy 1.0.3
font search path ['/usr/share/matplotlib/mpl-data/fonts/ttf',
'/usr/share/matplotlib/mpl-data/fonts/afm']
trying fontname /usr/share/matplotlib/mpl-data/fonts/ttf/cmex10.ttf
trying fontname /usr/share/matplotlib/mpl-data/fonts/ttf/cmr10.ttf
trying fontname /usr/share/matplotlib/mpl-data/fonts/ttf/cmmi10.ttf
trying fontname /usr/share/matplotlib/mpl-data/fonts/ttf/cmsy10.ttf
trying fontname /usr/share/matplotlib/mpl-data/fonts/ttf/cmtt10.ttf
trying fontname /usr/share/matplotlib/mpl-data/fonts/ttf/ARIALUNI.TTF
trying fontname /usr/share/fonts/truetype/ttf-sil-padauk/Padauk-Bold.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/Times_New_Roman.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/verdanai.ttf
trying fontname /usr/share/fonts/truetype/freefont/FreeSerif.ttf
trying fontname /usr/share/fonts/truetype/ttf-dejavu/DejaVuSansCondensed.ttf
trying fontname /usr/share/fonts/truetype/ttf-sil-andika/AndikaDesRevG.ttf
trying fontname /usr/share/fonts/truetype/ttf-dejavu/DejaVuSansMono.ttf
trying fontname /usr/share/fonts/truetype/ttf-lucida/LucidaBrightRegular.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/Georgia_Bold.ttf
trying fontname /usr/share/fonts/truetype/freefont/FreeSerifBold.ttf
trying fontname /usr/share/fonts/truetype/ttf-sil-andika/AndikaDesRevE.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/georgiab.ttf
trying fontname /usr/share/fonts/truetype/ttf-dejavu/DejaVuSerif-Bold.ttf
trying fontname /usr/share/fonts/truetype/freefont/FreeSansOblique.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/Comic_Sans_MS_Bold.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/Courier_New_Bold.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/Georgia_Bold_Italic.ttf
trying fontname /usr/share/fonts/truetype/ttf-sil-andika/AndikaDesRevC.ttf
trying fontname /usr/share/fonts/truetype/ttf-dejavu/DejaVuSans-Oblique.ttf
trying fontname /usr/share/fonts/truetype/ttf-lucida/LucidaBrightDemiItalic.ttf
trying fontname
/usr/share/fonts/truetype/msttcorefonts/Times_New_Roman_Bold_Italic.ttf
trying fontname /usr/share/fonts/truetype/ttf-dejavu/DejaVuSans-BoldOblique.ttf
trying fontname /usr/share/fonts/truetype/ttf-dejavu/DejaVuSerif-Italic.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/Impact.ttf
trying fontname
/usr/share/fonts/truetype/ttf-dejavu/DejaVuSansCondensed-BoldOblique.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/Georgia.ttf
trying fontname
/usr/share/fonts/truetype/ttf-dejavu/DejaVuSansCondensed-Bold.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/andalemo.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/arialbi.ttf
trying fontname /usr/share/fonts/truetype/ttf-sil-andika/AndikaDesRevB.ttf
trying fontname /usr/share/fonts/truetype/ttf-lucida/LucidaSansOblique.ttf
trying fontname /usr/share/fonts/truetype/ttf-junicode/Junicode-Bold.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/Verdana.ttf
trying fontname /usr/share/fonts/truetype/ttf-dejavu/DejaVuSansMono-Bold.ttf
trying fontname
/usr/share/fonts/truetype/ttf-dejavu/DejaVuSansCondensed-Oblique.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/cour.ttf
trying fontname
/usr/share/fonts/truetype/ttf-lucida/LucidaTypewriterBoldOblique.ttf
trying fontname /usr/share/fonts/truetype/ttf-thryomanes/thryrg__.ttf
trying fontname /usr/share/fonts/truetype/ttf-dejavu/DejaVuSerif-BoldItalic.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/courbd.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/Trebuchet_MS.ttf
trying fontname /usr/share/fonts/truetype/ttf-thryomanes/thrybi__.ttf
trying fontname
/usr/share/fonts/truetype/ttf-dejavu/DejaVuSerifCondensed-Bold.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/Trebuchet_MS_Italic.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/Courier_New.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/comicbd.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/Arial.ttf
trying fontname /usr/share/fonts/truetype/ttf-lucida/LucidaBrightItalic.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/courbi.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/times.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/Verdana_Italic.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/georgia.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/trebuc.ttf
trying fontname /usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf
trying fontname /usr/share/fonts/truetype/freefont/FreeSansBold.ttf
trying fontname
/usr/share/fonts/truetype/ttf-dejavu/DejaVuSansMono-BoldOblique.ttf
trying fontname /usr/share/fonts/truetype/freefont/FreeMonoBold.ttf
trying fontname /usr/share/fonts/truetype/ttf-dejavu/DejaVuSans-Bold.ttf
trying fontname /usr/share/fonts/truetype/ttf-dejavu/DejaVuSans-ExtraLight.ttf
trying fontname /usr/share/fonts/truetype/ttf-junicode/Junicode-Regular.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/verdanaz.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/georgiai.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/Andale_Mono.ttf
trying fontname /usr/share/fonts/truetype/ttf-lucida/LucidaSansRegular.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/Georgia_Italic.ttf
trying fontname /usr/share/fonts/truetype/kochi/kochi-mincho.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/Courier_New_Italic.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/couri.ttf
trying fontname
/usr/share/fonts/truetype/ttf-dejavu/DejaVuSerifCondensed-BoldItalic.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/ariblk.ttf
trying fontname /usr/share/fonts/truetype/openoffice/opens___.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/Verdana_Bold_Italic.ttf
trying fontname /usr/share/fonts/truetype/ttf-sil-andika/AndikaDesRevD.ttf
trying fontname
/usr/share/fonts/truetype/ttf-dejavu/DejaVuSerifCondensed-Italic.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/Arial_Black.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/Webdings.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/Verdana_Bold.ttf
trying fontname /usr/share/fonts/truetype/ttf-lucida/LucidaTypewriterOblique.ttf
trying fontname /usr/share/fonts/truetype/freefont/FreeSansBoldOblique.ttf
trying fontname /usr/share/fonts/truetype/ttf-sil-padauk/Padauk.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/Arial_Italic.ttf
trying fontname /usr/share/fonts/truetype/freefont/FreeMonoBoldOblique.ttf
trying fontname /usr/share/fonts/truetype/ttf-junicode/Junicode-Italic.ttf
trying fontname /usr/share/fonts/truetype/freefont/FreeSans.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/ariali.ttf
trying fontname /usr/share/fonts/truetype/freefont/FreeSerifBoldItalic.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/trebucbi.ttf
trying fontname /usr/share/fonts/truetype/ttf-lucida/LucidaTypewriterBold.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/timesi.ttf
trying fontname
/usr/share/fonts/truetype/msttcorefonts/Times_New_Roman_Italic.ttf
trying fontname /usr/share/fonts/truetype/ttf-lucida/LucidaBrightDemiBold.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/georgiaz.ttf
trying fontname
/usr/share/fonts/truetype/msttcorefonts/Courier_New_Bold_Italic.ttf
trying fontname /usr/share/fonts/truetype/ttf-thryomanes/thryb___.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/arialbd.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/timesbd.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/Trebuchet_MS_Bold.ttf
trying fontname /usr/share/fonts/truetype/ttf-dejavu/DejaVuSerif.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/verdana.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/arial.ttf
trying fontname /usr/share/fonts/truetype/freefont/FreeMonoOblique.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/comic.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/webdings.ttf
trying fontname /usr/share/fonts/truetype/ttf-dejavu/DejaVuSansMono-Oblique.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/Arial_Bold.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/trebucit.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/timesbi.ttf
trying fontname /usr/share/fonts/truetype/ttf-thryomanes/thryi___.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/Comic_Sans_MS.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/Arial_Bold_Italic.ttf
trying fontname /usr/share/fonts/truetype/ttf-dejavu/DejaVuSerifCondensed.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/impact.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/verdanab.ttf
trying fontname
/usr/share/fonts/truetype/msttcorefonts/Trebuchet_MS_Bold_Italic.ttf
trying fontname /usr/share/fonts/truetype/ttf-lucida/LucidaSansDemiOblique.ttf
trying fontname /usr/share/fonts/truetype/kochi/kochi-mincho-subst.ttf
trying fontname /usr/share/fonts/truetype/ttf-junicode/Junicode-BoldItalic.ttf
trying fontname /usr/share/fonts/truetype/freefont/FreeMono.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/trebucbd.ttf
trying fontname /usr/share/fonts/truetype/freefont/FreeSerifItalic.ttf
trying fontname /usr/share/fonts/truetype/ttf-lucida/LucidaTypewriterRegular.ttf
trying fontname /usr/share/fonts/truetype/ttf-lucida/LucidaSansDemiBold.ttf
trying fontname /usr/share/fonts/truetype/ttf-sil-andika/AndikaDesRevA.ttf
trying fontname /usr/share/fonts/truetype/ttf-sil-andika/AndikaDesRevF.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/Times_New_Roman_Bold.ttf
$HOME=/home/hobbes
CONFIGDIR=/home/hobbes/.matplotlib
loaded ttfcache file /home/hobbes/.matplotlib/ttffont.cache
matplotlib data path /usr/share/matplotlib/mpl-data
Could not load matplotlib icon: Couldn't recognize the image file
format for file '/usr/share/matplotlib/mpl-data/images/matplotlib.svg'
backend GTKAgg version 2.10.6
FigureCanvasAgg.draw
RendererAgg.__init__
RendererAgg.__init__ width=640.0, height=480.0
RendererAgg.__init__ _RendererAgg done
RendererAgg.__init__ done
RendererAgg._get_agg_font
  findfont failed FOOFOOFOO
Could not match FOOFOOFOO, normal, normal. Returning
/usr/share/matplotlib/mpl-data/fonts/ttf/cmex10.ttf
RendererAgg._get_agg_font
RendererAgg.draw_text
RendererAgg._get_agg_font
RendererAgg.points_to_pixels
RendererAgg.points_to_pixels
RendererAgg._get_agg_font
RendererAgg._get_agg_font
RendererAgg.draw_text
RendererAgg._get_agg_font
RendererAgg.points_to_pixels
RendererAgg.points_to_pixels
RendererAgg._get_agg_font
RendererAgg._get_agg_font
RendererAgg.draw_text
RendererAgg._get_agg_font
RendererAgg.points_to_pixels
RendererAgg.points_to_pixels
RendererAgg._get_agg_font
RendererAgg._get_agg_font
RendererAgg.draw_text
RendererAgg._get_agg_font
RendererAgg.points_to_pixels
RendererAgg.points_to_pixels
RendererAgg._get_agg_font
RendererAgg._get_agg_font
RendererAgg.draw_text
RendererAgg._get_agg_font
RendererAgg.points_to_pixels
RendererAgg.points_to_pixels
RendererAgg._get_agg_font
RendererAgg._get_agg_font
RendererAgg.draw_text
RendererAgg._get_agg_font
RendererAgg._get_agg_font
RendererAgg._get_agg_font
RendererAgg.draw_text
RendererAgg._get_agg_font
RendererAgg._get_agg_font
RendererAgg._get_agg_font
RendererAgg.draw_text
RendererAgg._get_agg_font
RendererAgg.points_to_pixels
RendererAgg.points_to_pixels
RendererAgg._get_agg_font
RendererAgg._get_agg_font
RendererAgg.draw_text
RendererAgg._get_agg_font
RendererAgg.points_to_pixels
RendererAgg.points_to_pixels
RendererAgg._get_agg_font
RendererAgg._get_agg_font
RendererAgg.draw_text
RendererAgg._get_agg_font
RendererAgg.points_to_pixels
RendererAgg.points_to_pixels
RendererAgg._get_agg_font
RendererAgg._get_agg_font
RendererAgg.draw_text
RendererAgg._get_agg_font
RendererAgg.points_to_pixels
RendererAgg.points_to_pixels
RendererAgg._get_agg_font
RendererAgg._get_agg_font
RendererAgg.draw_text
RendererAgg._get_agg_font
RendererAgg.points_to_pixels
RendererAgg.points_to_pixels
RendererAgg._get_agg_font
RendererAgg._get_agg_font
RendererAgg.draw_text
RendererAgg._get_agg_font
RendererAgg._get_agg_font
RendererAgg._get_agg_font
RendererAgg.draw_text
RendererAgg._get_agg_font
RendererAgg._get_agg_font
  findfont failed FOOFOOFOO, normal, normal 400, normal, 14.0
Could not match FOOFOOFOO, normal, normal. Returning
/usr/share/matplotlib/mpl-data/fonts/ttf/cmex10.ttf
RendererAgg._get_agg_font
RendererAgg.draw_text
RendererAgg._get_agg_font
FigureCanvasAgg.buffer_rgba
RendererAgg.buffer_rgba

···

On 10/1/07, Michael Droettboom <mdroe@...86...> wrote:

We can first try to track down whether the Arial MS Unicode font is
getting picked up. In your matplotlibrc, can you add:

   verbose: debug-annoying

David Loyall wrote:

We can first try to track down whether the Arial MS Unicode font is
getting picked up. In your matplotlibrc, can you add:

   verbose: debug-annoying

Michael,

Thank you. Interesting results:

With verbose.level set to debug-annoying, these lines look significant:
       findfont failed Arial Unicode MS, normal, normal 500, normal, 14.0
Could not match Arial Unicode MS, normal, normal. Returning
/usr/share/matplotlib/mpl-data/fonts/ttf/cmex10.ttf

Well, I played around with this a little more and found the problem!
The font.weight of 'medium' (500) is what could not be found. When I
switched font.weight to 'normal' (400) in matplotlibrc, it worked and
the graph was rendered with the correct glyph. (This worked for the
DejaVu Sans font, still no luck with Arial Unicode MS, but, that's
fine.)

So, problem solved, thanks again! :slight_smile:

Great to know the problem is solved in your particular instance. In general, though, the font-finding algorithm is being a bit too strict. Currently there's no sense of "weighting of properties" in the way it looks up fonts -- it should probably do something to the effect that a match of the name is more important than a match in the weight. As it stands now, if it doesn't find an exact match it throws up its hands and just grabs the first available font... There is some experimental support for using fontconfig (the more-or-less standard way to look up fonts on Linux these days) in SVN of matplotlib -- hopefully by the next release some of these things will be worked out.

Here's something I noticed: When I copied ARIALUNI.TTF into
/usr/share/matplotlib/mpl-data/fonts/ttf/ and ran the test plot, all
the characters are gibberish. Actually, they are glyphs, but, the
wrong ones. The same thing happens if I copy Thyromanes .ttf files
into that directory, or if I put those files in the $TTFPATH
directory. In fact, it also happens if I copy andalemo.ttf, and that
font doesn't include extra unicode characters.

So, I'll paste the entire debug-annoying output that occurred when I
was getting the gibberish text on the plot at the end of this email.
As you can see, I set the font to a nonsense string to illustrate that
the problem occurs even if the extra font in the directory isn't being
requested. Also, I made sure that the extra font wasn't duplicated
anywhere else in the search path.

The problem is in this line:

   /usr/share/matplotlib/mpl-data/fonts/ttf/cmex10.ttf

That's Computer Modern "Extra Symbols" which is mainly comprised of characters for composing math equations -- there's no "letters" in there at all. When matplotlib doesn't find an exact match for a font, it's supposed to default to Vera Sans. In all your experimentation, did you perhaps delete the Vera Sans that comes with matplotlib? (It doesn't look like it was in the search path.) Restoring that file should at least remove the "gibberish" problem, but you still won't get the fonts you want. You'll (unfortunately) have to do like you did with Arial Unicode and set all the parameters correctly.

(You may need to delete your font cache in ~/.matplotlib/ttffont.cache as well.)

Cheers,
Mike

···

On 10/1/07, Michael Droettboom <mdroe@...86...> wrote:

loaded rc file /home/hobbes/.matplotlib/matplotlibrc
matplotlib version 0.90.1
verbose.level debug-annoying
interactive is False
units is False
platform is linux2
loaded modules: ['_bisect', 'distutils', 'pylab', 'datetime',
'matplotlib.tempfile', 'distutils.sysconfig', 'pytz.datetime',
'pytz.cStringIO', 'struct', 'tempfile', 'imp', 'pytz.os', 'zipimport',
'string', 'encodings.utf_8', 'matplotlib.__future__', 'pytz.tzinfo',
'distutils.re', 'bisect', 'signal', 'random', 'token',
'matplotlib.pytz', 'dis', 'pytz.tzfile', 'cStringIO', 'locale',
'encodings', 'dateutil', 'matplotlib.warnings', 'pytz.pytz',
'matplotlib.sys', 're', 'math', 'fcntl', 'UserDict', 'inspect',
'distutils.os', 'matplotlib', 'codecs', 'md5', '_locale',
'matplotlib.os', 'thread', 'sre', 'itertools', 'opcode',
'distutils.sys', 'os', '__future__', '_sre', '__builtin__',
'matplotlib.re', 'distutils.string', 'matplotlib.datetime',
'posixpath', 'errno', 'binascii', 'sre_constants', 'matplotlib.md5',
'types', 'pytz.sys', 'tokenize', '_codecs', 'pytz', 'copy',
'matplotlib.dateutil', 'posix', 'encodings.aliases', 'exceptions',
'sre_parse', 'pytz.bisect', 'copy_reg', 'sre_compile', '_random',
'pytz.struct', 'site', '__main__', 'shutil', 'strop',
'encodings.codecs', 'gettext', 'encodings.exceptions', 'pytz.sets',
'stat', 'warnings', 'encodings.types', 'sys', 'os.path',
'pytz.gettext', 'matplotlib.distutils', 'distutils.errors',
'linecache', 'matplotlib.shutil', 'sets']
numerix numpy 1.0.3
font search path ['/usr/share/matplotlib/mpl-data/fonts/ttf',
'/usr/share/matplotlib/mpl-data/fonts/afm']
trying fontname /usr/share/matplotlib/mpl-data/fonts/ttf/cmex10.ttf
trying fontname /usr/share/matplotlib/mpl-data/fonts/ttf/cmr10.ttf
trying fontname /usr/share/matplotlib/mpl-data/fonts/ttf/cmmi10.ttf
trying fontname /usr/share/matplotlib/mpl-data/fonts/ttf/cmsy10.ttf
trying fontname /usr/share/matplotlib/mpl-data/fonts/ttf/cmtt10.ttf
trying fontname /usr/share/matplotlib/mpl-data/fonts/ttf/ARIALUNI.TTF
trying fontname /usr/share/fonts/truetype/ttf-sil-padauk/Padauk-Bold.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/Times_New_Roman.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/verdanai.ttf
trying fontname /usr/share/fonts/truetype/freefont/FreeSerif.ttf
trying fontname /usr/share/fonts/truetype/ttf-dejavu/DejaVuSansCondensed.ttf
trying fontname /usr/share/fonts/truetype/ttf-sil-andika/AndikaDesRevG.ttf
trying fontname /usr/share/fonts/truetype/ttf-dejavu/DejaVuSansMono.ttf
trying fontname /usr/share/fonts/truetype/ttf-lucida/LucidaBrightRegular.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/Georgia_Bold.ttf
trying fontname /usr/share/fonts/truetype/freefont/FreeSerifBold.ttf
trying fontname /usr/share/fonts/truetype/ttf-sil-andika/AndikaDesRevE.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/georgiab.ttf
trying fontname /usr/share/fonts/truetype/ttf-dejavu/DejaVuSerif-Bold.ttf
trying fontname /usr/share/fonts/truetype/freefont/FreeSansOblique.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/Comic_Sans_MS_Bold.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/Courier_New_Bold.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/Georgia_Bold_Italic.ttf
trying fontname /usr/share/fonts/truetype/ttf-sil-andika/AndikaDesRevC.ttf
trying fontname /usr/share/fonts/truetype/ttf-dejavu/DejaVuSans-Oblique.ttf
trying fontname /usr/share/fonts/truetype/ttf-lucida/LucidaBrightDemiItalic.ttf
trying fontname
/usr/share/fonts/truetype/msttcorefonts/Times_New_Roman_Bold_Italic.ttf
trying fontname /usr/share/fonts/truetype/ttf-dejavu/DejaVuSans-BoldOblique.ttf
trying fontname /usr/share/fonts/truetype/ttf-dejavu/DejaVuSerif-Italic.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/Impact.ttf
trying fontname
/usr/share/fonts/truetype/ttf-dejavu/DejaVuSansCondensed-BoldOblique.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/Georgia.ttf
trying fontname
/usr/share/fonts/truetype/ttf-dejavu/DejaVuSansCondensed-Bold.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/andalemo.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/arialbi.ttf
trying fontname /usr/share/fonts/truetype/ttf-sil-andika/AndikaDesRevB.ttf
trying fontname /usr/share/fonts/truetype/ttf-lucida/LucidaSansOblique.ttf
trying fontname /usr/share/fonts/truetype/ttf-junicode/Junicode-Bold.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/Verdana.ttf
trying fontname /usr/share/fonts/truetype/ttf-dejavu/DejaVuSansMono-Bold.ttf
trying fontname
/usr/share/fonts/truetype/ttf-dejavu/DejaVuSansCondensed-Oblique.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/cour.ttf
trying fontname
/usr/share/fonts/truetype/ttf-lucida/LucidaTypewriterBoldOblique.ttf
trying fontname /usr/share/fonts/truetype/ttf-thryomanes/thryrg__.ttf
trying fontname /usr/share/fonts/truetype/ttf-dejavu/DejaVuSerif-BoldItalic.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/courbd.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/Trebuchet_MS.ttf
trying fontname /usr/share/fonts/truetype/ttf-thryomanes/thrybi__.ttf
trying fontname
/usr/share/fonts/truetype/ttf-dejavu/DejaVuSerifCondensed-Bold.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/Trebuchet_MS_Italic.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/Courier_New.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/comicbd.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/Arial.ttf
trying fontname /usr/share/fonts/truetype/ttf-lucida/LucidaBrightItalic.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/courbi.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/times.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/Verdana_Italic.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/georgia.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/trebuc.ttf
trying fontname /usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf
trying fontname /usr/share/fonts/truetype/freefont/FreeSansBold.ttf
trying fontname
/usr/share/fonts/truetype/ttf-dejavu/DejaVuSansMono-BoldOblique.ttf
trying fontname /usr/share/fonts/truetype/freefont/FreeMonoBold.ttf
trying fontname /usr/share/fonts/truetype/ttf-dejavu/DejaVuSans-Bold.ttf
trying fontname /usr/share/fonts/truetype/ttf-dejavu/DejaVuSans-ExtraLight.ttf
trying fontname /usr/share/fonts/truetype/ttf-junicode/Junicode-Regular.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/verdanaz.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/georgiai.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/Andale_Mono.ttf
trying fontname /usr/share/fonts/truetype/ttf-lucida/LucidaSansRegular.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/Georgia_Italic.ttf
trying fontname /usr/share/fonts/truetype/kochi/kochi-mincho.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/Courier_New_Italic.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/couri.ttf
trying fontname
/usr/share/fonts/truetype/ttf-dejavu/DejaVuSerifCondensed-BoldItalic.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/ariblk.ttf
trying fontname /usr/share/fonts/truetype/openoffice/opens___.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/Verdana_Bold_Italic.ttf
trying fontname /usr/share/fonts/truetype/ttf-sil-andika/AndikaDesRevD.ttf
trying fontname
/usr/share/fonts/truetype/ttf-dejavu/DejaVuSerifCondensed-Italic.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/Arial_Black.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/Webdings.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/Verdana_Bold.ttf
trying fontname /usr/share/fonts/truetype/ttf-lucida/LucidaTypewriterOblique.ttf
trying fontname /usr/share/fonts/truetype/freefont/FreeSansBoldOblique.ttf
trying fontname /usr/share/fonts/truetype/ttf-sil-padauk/Padauk.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/Arial_Italic.ttf
trying fontname /usr/share/fonts/truetype/freefont/FreeMonoBoldOblique.ttf
trying fontname /usr/share/fonts/truetype/ttf-junicode/Junicode-Italic.ttf
trying fontname /usr/share/fonts/truetype/freefont/FreeSans.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/ariali.ttf
trying fontname /usr/share/fonts/truetype/freefont/FreeSerifBoldItalic.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/trebucbi.ttf
trying fontname /usr/share/fonts/truetype/ttf-lucida/LucidaTypewriterBold.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/timesi.ttf
trying fontname
/usr/share/fonts/truetype/msttcorefonts/Times_New_Roman_Italic.ttf
trying fontname /usr/share/fonts/truetype/ttf-lucida/LucidaBrightDemiBold.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/georgiaz.ttf
trying fontname
/usr/share/fonts/truetype/msttcorefonts/Courier_New_Bold_Italic.ttf
trying fontname /usr/share/fonts/truetype/ttf-thryomanes/thryb___.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/arialbd.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/timesbd.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/Trebuchet_MS_Bold.ttf
trying fontname /usr/share/fonts/truetype/ttf-dejavu/DejaVuSerif.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/verdana.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/arial.ttf
trying fontname /usr/share/fonts/truetype/freefont/FreeMonoOblique.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/comic.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/webdings.ttf
trying fontname /usr/share/fonts/truetype/ttf-dejavu/DejaVuSansMono-Oblique.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/Arial_Bold.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/trebucit.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/timesbi.ttf
trying fontname /usr/share/fonts/truetype/ttf-thryomanes/thryi___.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/Comic_Sans_MS.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/Arial_Bold_Italic.ttf
trying fontname /usr/share/fonts/truetype/ttf-dejavu/DejaVuSerifCondensed.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/impact.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/verdanab.ttf
trying fontname
/usr/share/fonts/truetype/msttcorefonts/Trebuchet_MS_Bold_Italic.ttf
trying fontname /usr/share/fonts/truetype/ttf-lucida/LucidaSansDemiOblique.ttf
trying fontname /usr/share/fonts/truetype/kochi/kochi-mincho-subst.ttf
trying fontname /usr/share/fonts/truetype/ttf-junicode/Junicode-BoldItalic.ttf
trying fontname /usr/share/fonts/truetype/freefont/FreeMono.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/trebucbd.ttf
trying fontname /usr/share/fonts/truetype/freefont/FreeSerifItalic.ttf
trying fontname /usr/share/fonts/truetype/ttf-lucida/LucidaTypewriterRegular.ttf
trying fontname /usr/share/fonts/truetype/ttf-lucida/LucidaSansDemiBold.ttf
trying fontname /usr/share/fonts/truetype/ttf-sil-andika/AndikaDesRevA.ttf
trying fontname /usr/share/fonts/truetype/ttf-sil-andika/AndikaDesRevF.ttf
trying fontname /usr/share/fonts/truetype/msttcorefonts/Times_New_Roman_Bold.ttf
$HOME=/home/hobbes
CONFIGDIR=/home/hobbes/.matplotlib
loaded ttfcache file /home/hobbes/.matplotlib/ttffont.cache
matplotlib data path /usr/share/matplotlib/mpl-data
Could not load matplotlib icon: Couldn't recognize the image file
format for file '/usr/share/matplotlib/mpl-data/images/matplotlib.svg'
backend GTKAgg version 2.10.6
FigureCanvasAgg.draw
RendererAgg.__init__
RendererAgg.__init__ width=640.0, height=480.0
RendererAgg.__init__ _RendererAgg done
RendererAgg.__init__ done
RendererAgg._get_agg_font
  findfont failed FOOFOOFOO
Could not match FOOFOOFOO, normal, normal. Returning
/usr/share/matplotlib/mpl-data/fonts/ttf/cmex10.ttf
RendererAgg._get_agg_font
RendererAgg.draw_text
RendererAgg._get_agg_font
RendererAgg.points_to_pixels
RendererAgg._get_agg_font
RendererAgg.draw_text
RendererAgg._get_agg_font
RendererAgg.points_to_pixels
RendererAgg._get_agg_font
RendererAgg.draw_text
RendererAgg._get_agg_font
RendererAgg.points_to_pixels
RendererAgg._get_agg_font
RendererAgg.draw_text
RendererAgg._get_agg_font
RendererAgg.points_to_pixels
RendererAgg._get_agg_font
RendererAgg.draw_text
RendererAgg._get_agg_font
RendererAgg.points_to_pixels
RendererAgg._get_agg_font
RendererAgg.draw_text
RendererAgg._get_agg_font
RendererAgg.draw_text
RendererAgg._get_agg_font
RendererAgg.draw_text
RendererAgg._get_agg_font
RendererAgg.points_to_pixels
RendererAgg._get_agg_font
RendererAgg.draw_text
RendererAgg._get_agg_font
RendererAgg.points_to_pixels
RendererAgg._get_agg_font
RendererAgg.draw_text
RendererAgg._get_agg_font
RendererAgg.points_to_pixels
RendererAgg._get_agg_font
RendererAgg.draw_text
RendererAgg._get_agg_font
RendererAgg.points_to_pixels
RendererAgg._get_agg_font
RendererAgg.draw_text
RendererAgg._get_agg_font
RendererAgg.points_to_pixels
RendererAgg._get_agg_font
RendererAgg.draw_text
RendererAgg._get_agg_font
RendererAgg.draw_text
RendererAgg._get_agg_font
  findfont failed FOOFOOFOO, normal, normal 400, normal, 14.0
Could not match FOOFOOFOO, normal, normal. Returning
/usr/share/matplotlib/mpl-data/fonts/ttf/cmex10.ttf
RendererAgg._get_agg_font
RendererAgg.draw_text
RendererAgg._get_agg_font
FigureCanvasAgg.buffer_rgba
RendererAgg.buffer_rgba

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