ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 25 Jun 2012 11:00:49 +0200A bug in graphics.pyhttps://ask.sagemath.org/question/7508/a-bug-in-graphicspy/ Several hours ago I post my question about unicode support in "axes_labels",here is [my question](http://ask.sagemath.org/question/1557/why-sage-can-not-plot-chinese-label)<p>
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.<p>
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)"<p>
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 [].<p>
Why I can set the axes labels in Chinese with matplotlib but can not in sage? After I check the source code in <p>SAGE/local/lib/python2.7/site-packages/sage/plot/graphics.py<p>
In line 634 of the method "def axes_labels(self, l=None)",I found the line is <p>
self.__axes_labels = (str(l[0]), str(l[1]))<p>
It is obviously that the problem is caused by the str(),after change this line to <p>self.__axes_labels = (l[0], l[1])<p>
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).<p>
There is some work to do with matplotlibrc,it is in sage/local/lib/python/site-packages/matplotlib/mpl-data<p>
First,we need to download one free unicode font,more information can refer to [WikiPedia](http://en.wikipedia.org/wiki/Unicode_typefaces),and I use [Bitstream Cyberbit](http://en.fonts2u.com/download/bitstream-cyberbit.font) for a test.I think there are more better unicode fonts.Bitstream Cyberbit can work well with Chinese,Japanese,Korean in my test.<p>
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 <p>
font.family : sans-serif<p>
font.style : normal<p>
font.variant : normal<p>
font.weight : medium<p>
font.stretch : normal<p>
It seems that only sans-serif and serif can work well with unicode.<p>
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:<p>
font.sans-serif : Bitstream Cyberbit,Microsoft YaHei,Bitstream Vera Sans, Lucida Grande<p>
It also needs to remove the "#" in the begin of axes.unicode_minus,and set the boolean value to "False",for example:<p>
axes.unicode_minus : False <p>
Save this file and restart Sage,know we can test it with:<p>
plot(x,axes_labels=['z',u'???????'])
<p>It seems that this website does not support unicode.Don't forget the "u" .<p>
The Bitstream Cyberbit,though work well with unicode,I think it is not so beautiful.Maybe there is better one.<p>
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.
shahuwangMon, 25 Jun 2012 11:00:49 +0200https://ask.sagemath.org/question/7508/Why does graph plotting crop so aggressively, and what is a work-around?https://ask.sagemath.org/question/8016/why-does-graph-plotting-crop-so-aggressively-and-what-is-a-work-around/Surely, the Sage community is aware of this bug. For example, there is [this ticket](http://trac.sagemath.org/sage_trac/ticket/7299), in which the problem is supposed to be fixed. But it's not!
A patch is described: in `sage/graphs/graph_plot.py` we can add the line(?)
> `G._extra_kwds['axes_pad']=.05 `
Am I to change this value in order to fix this over-zealous cropping behavior? No matter what I do, in this regard, I still end up with graph vertices partially cut off.
What's the easy work-around? I would like to be able to plot `graphics_array` objects with several graphs (with their vertices clearly shown!).
(http://trac.sagemath.org/sage_trac/ticket/7299)Sammy BlackMon, 21 Mar 2011 14:00:06 +0100https://ask.sagemath.org/question/8016/