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.Fri, 21 Apr 2017 21:24:54 +0200UnicodeDecodeError in matplotlib if 'python' set instead of 'sage' in Notebookhttps://ask.sagemath.org/question/37364/unicodedecodeerror-in-matplotlib-if-python-set-instead-of-sage-in-notebook/Hello!
I am trying to make publication ready images for LaTeX in Sage with matplotlib (due to the complex nature of the plot) in Notebook.
I have a lot of numerical calculations (not symbolic) so I switch to 'python-mode' using drop-down list on top of the Worksheet (so it looks like 'File...', 'Action...', 'Data...', 'python') so that my constants would read as native python's data types not Sage's symbolic objects.
Now having the switch on top of the page in 'python' mode the following code:
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']}
rc('font', **font)
import matplotlib.pyplot as plt
plt.plot([1], [1])
plt.title(ur'Тест')
plt.savefig("test.png")
yields ether UnicodeDecodeError or the image with the text corrupted:
![example of the corrupted output](/upfiles/14928022812226123.png)
But if I switch to 'sage' on top of the page, it works as expected:
![example of the valid output](/upfiles/14928023491980951.png)
I have no idea how that switch on top of the page affects matplotlib's output, but would really like to be able to use Cyrillic (utf8) letters and 'python' mode **at the same time**.
P.S. That magical switch on top of the page is really painful since I also can not save Worksheets if they contain utf-8 characters: [as in this still unresolved issue](https://ask.sagemath.org/question/26167/unicodedecodeerror-in-notebook-server-if-worksheet-is-set-to-python-instead-of-sage/) :-( :-(
**UPDATE:** Tested the MWE above in Jupiter - seems to work properly! And due to inevitable migration to Jupiter, the problem seems not to be obsolete.Fri, 21 Apr 2017 21:24:54 +0200https://ask.sagemath.org/question/37364/unicodedecodeerror-in-matplotlib-if-python-set-instead-of-sage-in-notebook/