Ask Your Question
4

Is there a way to use non english symbols?

asked 2016-07-12 13:20:04 +0100

Sergey Pashinin gravatar image

updated 2023-01-09 23:59:40 +0100

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 16:07:53 +0100 )edit

Thanks for reporting !

tmonteil gravatar imagetmonteil ( 2016-07-13 12:21:24 +0100 )edit

2 Answers

Sort by » oldest newest most voted
1

answered 2016-07-12 16:09:18 +0100

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 12:42:54 +0100

Eugene gravatar image

updated 2016-08-18 12:44:22 +0100

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 15:22:27 +0100 )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 13:20:04 +0100

Seen: 920 times

Last updated: Aug 18 '16