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.


------------------------------------------------------------------------------
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

Reply via email to