Ask Your Question

Cyrillic text on the plot

asked 2014-04-13 13:52:33 +0200

v_2e gravatar image

updated 2015-01-14 11:58:16 +0200

FrédéricC gravatar image

Is it possible to add the Cyrillic text to the plot in Sage Notebook?

Currently I am trying to do somethink of this kind:

total_plot = plot(sin(x),-10,10)
total_plot += text("????????", (5,0.5)),3))

Sage gives the error message:

ValueError: matplotlib display text must have all code points < 128
or use Unicode strings

If I add the 'u' symbol before the string

total_plot += text(u"????????", (5,0.5))

I can only see the empty rectangles instead of the letters.

P.S. I saw this question, however, I am more interested in not using Matplotlib directly if possible.

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2014-04-14 08:14:14 +0200

AndreWin gravatar image

updated 2014-04-20 08:28:48 +0200

Please see --> Grafika sredsvami mathplotlib --> Razonoe --> Rusificatsia Mathplotlib. This page is on Russian but has fully documentation for your quesiton.

Shortly you need to do:

import matplotlib as mpl
mpl.rcParams[''] = 'fantasy'
mpl.rcParams['font.fantasy'] = 'Arial' # for Windows
mpl.rcParams['font.fantasy'] = 'Ubuntu' # for Ubuntu
mpl.rcParams['font.fantasy'] = 'Arial, Ubuntu' # for Windows and Ubuntu
plt.title(u'Your text in Russian')

P.S. is my project. I collect information on Russian how to work in Sage and regulate my own knowledge as well.

edit flag offensive delete link more


Thanks! It workes just fine. And since it does, I suggest you editing this answer by adding the minimum recipe for Sage Notebook: import matplotlib as mpl; mpl.rcParams[''] = 'fantasy'; mpl.rcParams['font.fantasy'] = 'Arial'; text(u"?????????",(1,1), figsize=(2,2))

v_2e gravatar imagev_2e ( 2014-04-14 14:47:21 +0200 )edit

I decided to give a link to full information for this question. Thanks for you comment!)

AndreWin gravatar imageAndreWin ( 2014-04-20 08:20:34 +0200 )edit

By the way, it is not necessary to use matplotlib directly, as you shown above (like 'plt.title...'). These settings are also applied to the sage native plotting functions such as 'plot', 'text' etc.

v_2e gravatar imagev_2e ( 2014-04-21 08:20:47 +0200 )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


Asked: 2014-04-13 13:52:33 +0200

Seen: 1,081 times

Last updated: Apr 20 '14