On 10/10/2010 03:13 PM, Benoit Gaillard 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')
Why are you setting the font family to "monospace" and "fantasy" here?
You need to set the font to something that will have the Chinese
characters, for example, by uncommenting the lines that set sans-serif
to "SimHei" above. (That should work, but I don't have a Chinese font
on my system to test with.)
Mike
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
--
Michael Droettboom
Science Software Branch
Space Telescope Science Institute
Baltimore, Maryland, USA
------------------------------------------------------------------------------
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