Ask Your Question
4

Is there a way to use non english symbols?

asked 2016-07-12 06:20:04 -0500

Sergey Pashinin gravatar image

updated 2016-07-12 09:22:11 -0500

tmonteil gravatar image

I try a simple command:

Graph({'Б':[1,2]}).plot().save("/tmp/plot.png")

but it fails:

/usr/lib/sagemath/local/lib/python2.7/site-packages/matplotlib-1.5.1-py2.7-linux-x86_64.egg/matplotlib/text.py in set_text(self, s)
   1204         ACCEPTS: string or anything printable with '%s' conversion.
   1205         """
-> 1206         self._text = '%s' % (s,)
   1207         self.stale = True
   1208 

UnicodeDecodeError: 'ascii' codec can't decode byte 0xd0 in position 0: ordinal not in range(128)

How can I draw a graph with not only english symbols?

edit retag flag offensive close merge delete

Comments

kcrisman gravatar imagekcrisman ( 2016-07-12 09:07:53 -0500 )edit

Thanks for reporting !

tmonteil gravatar imagetmonteil ( 2016-07-13 05:21:24 -0500 )edit

2 answers

Sort by » oldest newest most voted
1

answered 2016-07-12 09:09:18 -0500

kcrisman gravatar image

Apparently the way we use matplotlib doesn't allow non-ascii strings. See Trac 21008.

edit flag offensive delete link more
0

answered 2016-08-18 05:42:54 -0500

Eugene gravatar image

updated 2016-08-18 05:44:22 -0500

I've encountered the same problem attempting label axes with Cyrillic letters. In Sage 7.3 the following code:

plot(sin, 0, pi, axes_labels=(ur'Ось абсцисс $x$', ur'Ось ординат $y$'))

Yields warning and display dummy-characters instead of Cyrillic letters:

MathTextWarning: Font 'default' does not have a glyph for '\u0441' [U441]

After some testing I ended up with the following code to prepare graphics to include in LaTeX, and it works in Sage 7.3 with Cyrillic letters as well (possibly requires Computer Modern Unicode font to be installed):

from matplotlib import rc

rc('text', usetex=True)
rc('text.latex', unicode=True)
rc('text.latex', preamble='\usepackage[utf8]{inputenc}')
rc('text.latex', preamble='\usepackage[russian]{babel}')

font = {'family': 'serif',
        'serif': ['Computer Modern Unicode'],
        'size': 12,
        }

rc('font', **font)

plot(sin, 0, pi, axes_labels=(ur'Ось абсцисс $x$', ur'Ось ординат $y$'))

P.S. Before that issue resolved I had to rename all axes manually, so whoever fixed it or helped fixing it - many thanks!!!

edit flag offensive delete link more

Comments

I've created https://trac.sagemath.org/ticket/21282 for this issue. Thanks!

kcrisman gravatar imagekcrisman ( 2016-08-18 08:22:27 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2016-07-12 06:20:04 -0500

Seen: 107 times

Last updated: Aug 18 '16