# A bug in graphics.py

 2 Several hours ago I post my question about unicode support in "axes_labels",here is my question I am sure this is really a bug of sage,I don't know how to report this bug as the spreadsheets.google.com is block by Chinese government. As we know that Matplotlib supports unicode with some setting in "matplotlibrc",and I make it work with Chinese characters now.But when I want to set the axes labels to some Chinese characters with "axes_labels" attribute ,I got exception:"UnicodeEncodeError: 'ascii' codec can't encode character u'\u6211' in position 0: ordinal not in range(128)" After I changed some code in sage/local/lib/python/site.py,I set the default encoding to "utf-8",that exception never raise again.But the problem does not be solved as the Chinese characters shown in the axes labels all become boxs like []. Why I can set the axes labels in Chinese with matplotlib but can not in sage? After I check the source code in SAGE/local/lib/python2.7/site-packages/sage/plot/graphics.py In line 634 of the method "def axes_labels(self, l=None)",I found the line is self.__axes_labels = (str(l[0]), str(l[1])) It is obviously that the problem is caused by the str(),after change this line to self.__axes_labels = (l[0], l[1]) and remove the SAGE/local/lib/python2.7/site-packages/sage/plot/graphics.pyc,restart sage , I finally got this problem solved.Now Sage gets no problem to work with Chinese,or in other word,gets no problem to work with unicode(utf-8). There is some work to do with matplotlibrc,it is in sage/local/lib/python/site-packages/matplotlib/mpl-data First,we need to download one free unicode font,more information can refer to WikiPedia,and I use Bitstream Cyberbit for a test.I think there are more better unicode fonts.Bitstream Cyberbit can work well with Chinese,Japanese,Korean in my test. After unzip the downloaded file,get the Cyberbit.ttf and put it into sage/local/lib/python/site-packages/matplotlib/mpl-data/fonts/ttf.And then open the matplotlibrc,remove the "#" which at the begin of font.family : sans-serif font.style : normal font.variant : normal font.weight : medium font.stretch : normal It seems that only sans-serif and serif can work well with unicode. And then ,remove the "#" at the begin of "font.sans-serif " in line 129,add "Bitstream Cyberbit" after ":",it must put on the first,like: font.sans-serif : Bitstream Cyberbit,Microsoft YaHei,Bitstream Vera Sans, Lucida Grande It also needs to remove the "#" in the begin of axes.unicode_minus,and set the boolean value to "False",for example: axes.unicode_minus : False Save this file and restart Sage,know we can test it with: plot(x,axes_labels=['z',u'???????']) It seems that this website does not support unicode.Don't forget the "u" . The Bitstream Cyberbit,though work well with unicode,I think it is not so beautiful.Maybe there is better one. It seems there are also some problems with the LaTeX to deal with Chinese,I will check for it and post my solution. Sorry for my poor English , and wish to be understood. asked Jun 25 '12 shahuwang 75 ● 1 ● 10 http://www.shahuwang.com/ tmonteil 3573 ● 3 ● 37 ● 83 http://wiki.sagemath.org/... An unrelated, but useful, comment; "and remove the SAGE/local/lib/python2.7/site-packages/sage/plot/graphics.pyc,restart sage" is not necessary; if you just restart sage with the sage -b flag it should make the changes you made in graphics.py live.kcrisman (Jun 25 '12)I see that you post a problem in the "Trac 13161" of Korean , the problem is the same with me as matplotlib come with some fonts only support ASCII. So I think you should put more free fonts in matplotlib and make some change in matplotlibrcshahuwang (Jun 25 '12)Ah, so you are saying that we would need to include additional fonts?kcrisman (Jun 25 '12)I update my question with my solution posted.shahuwang (Jun 26 '12)@shahuwang: Hey, this Trac ticket has positive review now. I would love to be able to add your name as an author - and hence newest contributor to Sage! See http://trac.sagemath.org/sage_trac/ticket/13161#comment:11kcrisman (Jul 26 '12)

## 1 Answer:

 0 This seems to still be try in Sage 5.1.beta5. I've opened Trac 13161 for this. If you get an account there, you can even upload a patch (see the developer guide) and we can give you author credit! I'm wondering if that is the whole solution, by the way; we don't really want end users to need to do something with their rc files just to plot axes labels. posted Jun 25 '12 kcrisman 7427 ● 17 ● 76 ● 166 It takes some time to set the matplotlibrc file,as it come with no font that support Chinese.It seems that there are only fonts that support ASCII .I wish next released to get the matplotlibrc setted to support unicode and with some free fonts to support non-ASCII used countries such as China,Japan. Wish to help moreshahuwang (Jun 25 '12)You may be interested in the update http://trac.sagemath.org/sage_trac/ticket/13161#comment:4kcrisman (Jul 17 '12)This ticket now has positive review.kcrisman (Jul 26 '12)I see it,thanks to review it,wish I can help moreshahuwang (Jul 31 '12)Please do, by giving us your real name so that we can properly acknowledge you as one of the authors!kcrisman (Jul 31 '12) see 1 more comment

## Your answer

Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
[hide preview]

## Stats:

Asked: Jun 25 '12

Seen: 212 times

Last updated: Jun 26 '12

powered by ASKBOT version 0.7.22
Copyright Sage, 2010. Some rights reserved under creative commons license.