Actually, i must apologize By calling fonts by their real name eg: "WenQuanYi Zen Hei" (instead of wqy-microhei, their file name), i can display them. So no worries for issue 2. However, I do not manage to export the png to pdf or eps due to the following error:
"TrueType font is missing table" Is that due to my changing the font name from *.ttc to *.ttf? regards, benoit Quoting Benoit Gaillard <benoit.gaill...@univ-tlse2.fr>: > Hi, > > When looking in my fontFile.cache, i did not find any of > '/usr/share/fonts/truetype/wqy/wqy-zenhei.ttf', > '/usr/share/fonts/truetype/wqy/wqy-microhei.ttf' or simhei. this is why > i could not display the characters. > > I deleted the cache and re-lounched my script, so that mpl had to look > for the fonts and update the cache. It added the simhei fonts to the > list. I can now display chinese characters with the simhei font. > > I ran into 2 more issues: > - Simhei "has no glyph names", which prevents me from exporting into pdf > - I do not manage to make mpl take into account microhei and zenhei, > whereas i have them in > '/usr/share/fonts/truetype/wqy/wqy-microhei.ttc'. I changed their name > to '/usr/share/fonts/truetype/wqy/wqy-microhei.ttf', and now mpl finds > them. However they fail to display chinese characters > > So, thank you for your help, i managed to display chinese characters > but there are still some issues. Do you have any idea? > > Benoit > > > Quoting sunqiang <sunqi...@gmail.com>: > >> oh, only test it on Windows yet. both "sim hei"and "microsoft yahei" >> are fontname on Windows Platform. >> maybe just copy "Sim Hei" to font directory is not enough? no clue here. >> >> I just test the script on Linux (Ubuntu 8.04, Python 2.5, matplotlib >> 0.98.4) with the follow steps: >> 1, find the configure directory of matplotlib >> import matplotlib as mpl >> mpl.get_configdir() >> >> return "~/.matplotlib" >> 2, in the configure directory, there is a file "fontList.cache" >> I find this >> (dp294 >> ... >> S'WenQuanYi Zen Hei' >> ... >> S'/usr/share/fonts/truetype/wqy/wqy-zenhei.ttf' >> ... >> >> I just know WenQuanYi is a "Chinese font" >> http://packages.ubuntu.com/hardy/ttf-wqy-zenhei >> 3, replace "Sim Hei" in your original script with "WenQuanYi Zen Hei", >> now it can display Chinese. >> both methods still work(embed fontname argument, or set >> mpl.rcParams['font.sans-serif']) >> >> maybe you can find a font that support Chinese character on your >> platform with these steps and try again? >> >> On Tue, Oct 12, 2010 at 10:41 PM, Benoit Gaillard >> <benoit.gaill...@univ-tlse2.fr> wrote: >>> Thank you for your help, >>> >>> but it does not seem to work. >>> >>> I have downloaded simhei fonts and added it in my directory >>> /usr/shared/fonts/truetype but even by using >>> """fontname="simhei" """, >>> or: >>> """mpl.rcParams['font.sans-serif'] = ['SimHei'] >>> mpl.rcParams['axes.unicode_minus'] = False """ >>> >>> i still display empty boxes instead of chinese characters. >>> >>> It is worth noting that these chinese characters print well on the console >>> if i add the line: >>> """for ytic in ytics: >>> print ytic""" >>> >>> Unfortunately, apart from copying lines of code, i cannot do much with the >>> blog you mention, as i don't understand what is written in it. >>> >>> @Mike: "monospace" family is one that enables me to display accents of >>> french words, for the xticks. "fantasy" family was the last family i tried >>> for the chinese labels, but to no success. >>> >>> So, has anyone managed to do it? Is there something i am missing?, >>> >>> regards, >>> >>> Benoit. >>> >>> Quoting sunqiang <sunqi...@gmail.com>: >>> >>>> maybe change the line >>>> """axim.set_yticklabels(ytics,fontsize=15,family='fantasy')""" to >>>> """axim.set_yticklabels(ytics,fontsize=15, fontname= "simsun (founder >>>> extended)")""" >>>> (or replace fontname with "simhei" or "microsoft yahei") is enough. >>>> >>>> >>>> or, put these two lines: >>>> mpl.rcParams['font.sans-serif'] = ['SimHei'] >>>> mpl.rcParams['axes.unicode_minus'] = False >>>> >>>> there is a Chinese blog (not mine) maybe worth reading: >>>> http://hi.baidu.com/lijiangshui/blog/item/a0aad703cd65ee7e3812bb49.html >>>> >>>> hope this help >>>> >>>> On Mon, Oct 11, 2010 at 3:13 AM, Benoit Gaillard >>>> <benoit.gaill...@univ-tlse2.fr> wrote: >>>>> >>>>> Hi, >>>>> >>>>> How can one display Mandarin labels in a plot, as yticks_labels for >>>>> example? >>>>> It looks to me that there is no font in matplotlib that can display >>>>> Chinese >>>>> characters? I can display accentuation from 'utf8' but i could not find a >>>>> font family that would display Chinese characters. >>>>> >>>>> Here is an example of plot that displays empty boxes instead of Chinese >>>>> characters. In comments you can see various failed attempts: >>>>> >>>>> import matplotlib as mpl >>>>> from matplotlib import cm >>>>> from matplotlib import rc >>>>> #rc('font',**{'family':'sans-serif','sans-serif':['SimHei','Arial']}) >>>>> #mpl.rcParams['font.sans-serif'] = ['SimHei','Arial'] >>>>> import matplotlib.pyplot as plt >>>>> >>>>> matrix=[[skey+tkey for skey in [1,2]] for tkey in [1,2]] >>>>> fig = plt.figure() >>>>> axim = fig.add_subplot(111) >>>>> #ytics: caractères chinois en utf8 >>>>> ytics=['\xe6\x8a\xb1'.decode('utf8'),'\xe6\x93\x81'.decode('utf8')] >>>>> xtics=['d\xc3\xa9bo\xc3\xaeter'.decode('utf8'),'diviser'.decode('utf8')] >>>>> axim.imshow(matrix, cmap=cm.jet, interpolation='nearest',origin='lower') >>>>> axim.set_xticks(range(2)) >>>>> >>>>> axim.set_xticklabels(xtics,fontsize=15,rotation=25,ha='right',family='monospace') >>>>> axim.set_yticks(range(2)) >>>>> axim.set_yticklabels(ytics,fontsize=15,family='fantasy')#,fontname='AR PL >>>>> ungtiL GB') >>>>> plt.show() >>>>> >>>>> Thank you for your help, >>>>> >>>>> Benoit >>>>> >>>>> >>>>> >>>>> ---------------------------------------------------------------- >>>>> This message was sent using IMP, the Internet Messaging Program. >>>>> >>>>> >>>>> Hi, >>>>> >>>>> How can one display mandarin labels in a plot, as yticks_labels for >>>>> example? >>>>> It looks to me that there is no font in matplotlib that can display >>>>> chinese >>>>> characters? I can display accentuation from 'utf8' but i could not find a >>>>> font family that would display chinese characters. >>>>> >>>>> Here is an example of plot that displays empty boxes instead of chinese >>>>> characters. In comment you can see various failed attempts: >>>>> >>>>> import matplotlib as mpl >>>>> from matplotlib import cm >>>>> from matplotlib import rc >>>>> #rc('font',**{'family':'sans-serif','sans-serif':['SimHei','Arial']}) >>>>> #mpl.rcParams['font.sans-serif'] = ['SimHei','Arial'] >>>>> import matplotlib.pyplot as plt >>>>> >>>>> matrix=[[skey+tkey for skey in [1,2]] for tkey in [1,2]] >>>>> fig = plt.figure() >>>>> axim = fig.add_subplot(111) >>>>> #ytics: caractères chinois en utf8 >>>>> ytics=['\xe6\x8a\xb1'.decode('utf8'),'\xe6\x93\x81'.decode('utf8')] >>>>> >>>>> xtics=['d\xc3\xa9bo\xc3\xaeter'.decode('utf8'),'diviser'.decode('utf8')] >>>>> axim.imshow(matrix, cmap=cm.jet, interpolation='nearest', >>>>> origin='lower') >>>>> axim.set_xticks(range(2)) >>>>> axim.set_xticklabels(xtics, >>>>> fontsize=15,rotation=25,ha='right',family='monospace') >>>>> axim.set_yticks(range(2)) >>>>> >>>>> axim.set_yticklabels(ytics,fontsize=15,family='fantasy')#,fontname='AR >>>>> PL SungtiL GB') >>>>> plt.show() >>>>> >>>>> Thank you for your help, >>>>> >>>>> Benoit >>>>> >>>>> >>>>> ------------------------------------------------------------------------------ >>>>> Beautiful is writing same markup. Internet Explorer 9 supports >>>>> standards for HTML5, CSS3, SVG 1.1, ECMAScript5, and DOM L2 & L3. >>>>> Spend less time writing and rewriting code and more time creating great >>>>> experiences on the web. Be a part of the beta today. >>>>> http://p.sf.net/sfu/beautyoftheweb >>>>> _______________________________________________ >>>>> Matplotlib-users mailing list >>>>> Matplotlib-users@lists.sourceforge.net >>>>> https://lists.sourceforge.net/lists/listinfo/matplotlib-users >>>>> >>>>> >>>> >>> >>> >>> >>> ---------------------------------------------------------------- >>> This message was sent using IMP, the Internet Messaging Program. >>> >>> >> > > > > ---------------------------------------------------------------- > This message was sent using IMP, the Internet Messaging Program. ---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program. ------------------------------------------------------------------------------ Beautiful is writing same markup. Internet Explorer 9 supports standards for HTML5, CSS3, SVG 1.1, ECMAScript5, and DOM L2 & L3. Spend less time writing and rewriting code and more time creating great experiences on the web. Be a part of the beta today. http://p.sf.net/sfu/beautyoftheweb _______________________________________________ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users