From: Mark J. <mja...@es...> - 2012-02-06 23:54:06
|
Hi All, I am having trouble rendering my Unicode strings in matplotlib using the PDF backend. When I use certain fonts (like the Win 7 default), I get no complaints but the characters are not rendered.... When I use a font like Arial Unicode MS, that I know contains all the chars, then I get the error message below. I did in fact, find a tty file that would work with Chinese ("Microsoft YaHei"), but I would like to avoid trying to map font files to languages. Any info on this subject would be greatly appreciated. Here is a snippet that reproduces the error below... if you remove the fontproperties option to the PYLAB.xlabel() call then the error is avoided but the result is not rendered. Thanks so much! MJ import matplotlib.pyplot as PLT import pylab as PYLAB from matplotlib.backends.backend_pdf import PdfPages as PDF import matplotlib.font_manager as fm fontFile = r'C:\Windows\Fonts\ARIALUNI.TTF' fp1 = fm.FontProperties(fname=fontFile) reportFile = r'C:\Temp\TestUnicode.pdf' pdfOutput = PDF(reportFile) vals = range(100) PLT.plot(vals, vals, color = "r", linestyle = "-") mess = u'\u6B63\u5728\u8BFB\u53D6\u6570\u636E...' PYLAB.xlabel(mess, fontproperties = fp1) PLT.savefig(pdfOutput, format='pdf') PLT.close() pdfOutput.close() Traceback (most recent call last): File "C:\Data\CRs\10.1\MemLeak\matplotlib\Scripts\matplotlib_unicode.py", line 27, in <module> PLT.savefig(pdfOutput, format='pdf') File "C:\Python27\lib\site-packages\matplotlib\pyplot.py", line 472, in savefig return fig.savefig(*args, **kwargs) File "C:\Python27\lib\site-packages\matplotlib\figure.py", line 1173, in savefig self.canvas.print_figure(*args, **kwargs) File "C:\Python27\lib\site-packages\matplotlib\backend_bases.py", line 2027, in print_figure **kwargs) File "C:\Python27\lib\site-packages\matplotlib\backends\backend_pdf.py", line 2181, in print_pdf self.figure.draw(renderer) File "C:\Python27\lib\site-packages\matplotlib\artist.py", line 55, in draw_wrapper draw(artist, renderer, *args, **kwargs) File "C:\Python27\lib\site-packages\matplotlib\figure.py", line 886, in draw func(*args) File "C:\Python27\lib\site-packages\matplotlib\artist.py", line 55, in draw_wrapper draw(artist, renderer, *args, **kwargs) File "C:\Python27\lib\site-packages\matplotlib\axes.py", line 1983, in draw a.draw(renderer) File "C:\Python27\lib\site-packages\matplotlib\artist.py", line 55, in draw_wrapper draw(artist, renderer, *args, **kwargs) File "C:\Python27\lib\site-packages\matplotlib\axis.py", line 1054, in draw self.label.draw(renderer) File "C:\Python27\lib\site-packages\matplotlib\artist.py", line 55, in draw_wrapper draw(artist, renderer, *args, **kwargs) File "C:\Python27\lib\site-packages\matplotlib\text.py", line 587, in draw ismath=ismath) File "C:\Python27\lib\site-packages\matplotlib\backends\backend_pdf.py", line 1784, in draw_text return draw_text_woven(chunks) File "C:\Python27\lib\site-packages\matplotlib\backends\backend_pdf.py", line 1754, in draw_text_woven glyph_name = font.get_glyph_name(gind) RuntimeError: Face has no glyph names PS. I cannot use a different backend. |