First time here? Check out the FAQ!

Ask Your Question
4

Is there a way to use non english symbols?

asked 8 years ago

Sergey Pashinin gravatar image

updated 2 years ago

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?

Preview: (hide)

Comments

Thanks for reporting !

tmonteil gravatar imagetmonteil ( 8 years ago )

2 Answers

Sort by » oldest newest most voted
1

answered 8 years ago

kcrisman gravatar image

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

Preview: (hide)
link
0

answered 8 years ago

Eugene gravatar image

updated 8 years ago

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!!!

Preview: (hide)
link

Comments

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

kcrisman gravatar imagekcrisman ( 8 years ago )

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: 8 years ago

Seen: 946 times

Last updated: Aug 18 '16