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
In line 634 of the method "def axes_labels(self, l=None)",I found the line is
self.__axes_labels = (str(l), str(l))
It is obviously that the problem is caused by the str(),after change this line to
self.__axes_labels = (l, l)
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:
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.
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 '12kcrisman
6614 ● 13 ● 66 ● 149
Asked: Jun 25 '12
Seen: 186 times
Last updated: Jun 26 '12
powered by ASKBOT version 0.7.22
Copyright Sage, 2010. Some rights reserved under creative commons license.