如何使用西里尔文中的TEX代码渲染Matplotlib绘图

如何使用西里尔文中的TEX代码渲染Matplotlib绘图,matplotlib,tex,Matplotlib,Tex,我试图理解如何在图例中用西里尔文字描绘人物 轴似乎显示TeX字符,但图例中的文本使用默认字体。代码如下: import numpy as np import matplotlib matplotlib.use("pgf") import matplotlib.pyplot as plt matplotlib.rcParams['text.usetex'] = True %matplotlib inline x = np.linspace(-np.pi, np.pi, 256) y = [] f

我试图理解如何在图例中用西里尔文字描绘人物

轴似乎显示TeX字符,但图例中的文本使用默认字体。代码如下:

import numpy as np
import matplotlib
matplotlib.use("pgf")
import matplotlib.pyplot as plt
matplotlib.rcParams['text.usetex'] = True
%matplotlib inline

x = np.linspace(-np.pi, np.pi, 256)
y = []
for i in range(-100, 100):
    y += [np.cos(x + i)]


plt.xlim(-10, 10)
plt.ylim(-2, 2)
plt.xticks([-10, 0, 10])
plt.yticks()
plt.plot(x, y[0], color = 'red', linewidth = 2.5, linestyle = '-', label = 'style1')
plt.plot(x, y[1], color = 'blue', linewidth = 3, linestyle = '-', label = 'style2')
plt.legend()
将第一行(红色)的标签更改为西里尔文:

plt.plot(x, y[0], color = 'red', linewidth = 2.5, linestyle = '-', label = 'стил1')
给出以下错误:

回调出错。post_在0x00000202EDCA3AF8>处执行(对于post_执行):

~\anaconda3\lib\site packages\matplotlib\offsetbox.py in get\u extent\u offset(self,渲染器)
491
492 whd_列表=[c.get_范围(渲染器)
-->493表示c在self中。获取\u可见\u子项()
494
495如果不是whd_列表:
~\anaconda3\lib\site packages\matplotlib\offsetbox.py in(.0)
491
492 whd_列表=[c.get_范围(渲染器)
-->493表示c在self中。获取\u可见\u子项()
494
495如果不是whd_列表:
get_区段中的~\anaconda3\lib\site packages\matplotlib\offsetbox.py(self,渲染器)
284 def get_范围(自身、渲染器):
285“返回框的元组`width、height、xdescent、ydedscent`”
-->286 w,h,xd,yd,offset=self.get_extent_offset(渲染器)
287返回w、h、xd、yd
288
获取范围偏移量中的~\anaconda3\lib\site packages\matplotlib\offsetbox.py(自身,渲染器)
417
418 whd_列表=[c.get_范围(渲染器)
-->419表示c在self.get_visible_children()]
420 whd_列表=[(w,h,xd,(h-yd))表示whd_列表中的w,h,xd,yd]
421
~\anaconda3\lib\site packages\matplotlib\offsetbox.py in(.0)
417
418 whd_列表=[c.get_范围(渲染器)
-->419表示c在self.get_visible_children()]
420 whd_列表=[(w,h,xd,(h-yd))表示whd_列表中的w,h,xd,yd]
421
get_区段中的~\anaconda3\lib\site packages\matplotlib\offsetbox.py(self,渲染器)
284 def get_范围(自身、渲染器):
285“返回框的元组`width、height、xdescent、ydedscent`”
-->286 w,h,xd,yd,offset=self.get_extent_offset(渲染器)
287返回w、h、xd、yd
288
获取范围偏移量中的~\anaconda3\lib\site packages\matplotlib\offsetbox.py(自身,渲染器)
491
492 whd_列表=[c.get_范围(渲染器)
-->493表示c在self中。获取\u可见\u子项()
494
495如果不是whd_列表:
~\anaconda3\lib\site packages\matplotlib\offsetbox.py in(.0)
491
492 whd_列表=[c.get_范围(渲染器)
-->493表示c在self中。获取\u可见\u子项()
494
495如果不是whd_列表:
get_区段中的~\anaconda3\lib\site packages\matplotlib\offsetbox.py(self,渲染器)
875“lp”,self.\u text.\u fontproperties,ismath=False)
876
-->877 bbox,info,d=self.\u text.\u get\u布局(渲染器)
878 w,h=bbox.宽度,bbox.高度
879
~\anaconda3\lib\site packages\matplotlib\text.py in\u get\u布局(self,渲染器)
296如果清洁管线:
297 w,h,d=渲染器。获取文本宽度高度下降(
-->298清洁线,自身。_fontproperties,ismath=ismath)
299其他:
300 w=h=d=0
~\anaconda3\lib\site packages\matplotlib\backends\backend\agg.py in get\u text\u width\u height\u description(self、s、prop、ismath)
199 fontsize=prop.get_size_in_points()
200 w,h,d=texmanager.get\u text\u width\u height\u down(
-->201秒,字体大小,渲染器=自身)
202返回w、h、d
203
~\anaconda3\lib\site packages\matplotlib\texmanager.py in get\u text\u width\u height\u descent(self、tex、fontsize、renderer)
446其他:
447#使用dviread。它有时返回错误的下降。
-->448 dvifile=self.make\u dvi(tex,fontsize)
449带dviread.Dvi(dvifile,72*dpi_分数)作为Dvi:
450页,=dvi
make\u dvi中的~\anaconda3\lib\site packages\matplotlib\texmanager.py(self、tex、fontsize)
336自运行检查子流程(
337[“latex”、“-interaction=nonstopmode”、“-halt on error”,
-->338 texfile],tex)
339对于glob.glob(basefile+'*')中的fname:
340如果不是fname.endswith(('dvi','tex')):
子流程(self、command、tex)中的~\anaconda3\lib\site packages\matplotlib\texmanager.py
315 prog=命令[0],
316 tex=tex.encode('unicode_escape'),
-->317 exc=exc.output.decode('utf-8'))来自exc
318_log.debug(报告)
319返回报告
RuntimeError:latex无法处理以下字符串:
b'\\u0441\\u0442\\u0438\\u043b1'
以下是latex生成的完整报告:
这是pdfTeX,版本3.14159265-2.6-1.40.20(TeX Live 2019/W32TeX)(预加载格式=latex)
受限\已启用写18。
进入扩展模式
(c:/Users/Victor/.matplotlib/tex.cache/b6f49bb15be8eba85bb671cfafcfb49.tex
LaTeX2e修补程序级别5
L3编程层
(c:/texlive/2019/texmf dist/tex/latex/base/article.cls
文件类别:第2019/12/20条v1.4l标准乳胶文件类别
(c:/texlive/2019/texmf dist/tex/latex/base/size10.clo))
(c:/texlive/2019/texmf dist/tex/latex/type1cm/type1cm.sty)
(c:/texlive/2019/texmf dist/tex/latex/base/texcomp.sty)
(c:/texlive/2019/texmf dist/tex/latex/base/inputenc.sty)
(c:/texlive/2019/texmf dist/tex/latex/geometry/geometry.sty
(c:/texlive/2019/texmf dist/tex/latex/graphics/keyval.sty)
(c:/texlive/2019/texmf dist/tex/generic/iftex/ifvtex.sty
(c:/texlive/2019/texmf dist/tex/generic/iftex/iftex.sty)
包装几何警告:“h”方向超出规格。
`宽度(5058.9pt)被忽略。
包装几何警告:“v”方向超过规格。
`忽略高度”(5058.9pt)。
)(c:/texlive/2019/t
---------------------------------------------------------------------------
CalledProcessError                        Traceback (most recent call last)
~\anaconda3\lib\site-packages\matplotlib\texmanager.py in _run_checked_subprocess(self, command, tex)
    303                                              cwd=self.texcache,
--> 304                                              stderr=subprocess.STDOUT)
    305         except FileNotFoundError as exc:

~\anaconda3\lib\subprocess.py in check_output(timeout, *popenargs, **kwargs)
    410     return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
--> 411                **kwargs).stdout
    412 

~\anaconda3\lib\subprocess.py in run(input, capture_output, timeout, check, *popenargs, **kwargs)
    511             raise CalledProcessError(retcode, process.args,
--> 512                                      output=stdout, stderr=stderr)
    513     return CompletedProcess(process.args, retcode, stdout, stderr)

CalledProcessError: Command '['latex', '-interaction=nonstopmode', '--halt-on-error', 'C:\\Users\\Victor\\.matplotlib\\tex.cache\\b6f49bb15be8eba85bb671cfafccfb49.tex']' returned non-zero exit status 1.

The above exception was the direct cause of the following exception:

RuntimeError                              Traceback (most recent call last)
~\anaconda3\lib\site-packages\matplotlib\pyplot.py in post_execute()
    107             def post_execute():
    108                 if matplotlib.is_interactive():
--> 109                     draw_all()
    110 
    111             # IPython >= 2

~\anaconda3\lib\site-packages\matplotlib\_pylab_helpers.py in draw_all(cls, force)
    126         for f_mgr in cls.get_all_fig_managers():
    127             if force or f_mgr.canvas.figure.stale:
--> 128                 f_mgr.canvas.draw_idle()
    129 
    130 atexit.register(Gcf.destroy_all)

~\anaconda3\lib\site-packages\matplotlib\backend_bases.py in draw_idle(self, *args, **kwargs)
   1914         if not self._is_idle_drawing:
   1915             with self._idle_draw_cntx():
-> 1916                 self.draw(*args, **kwargs)
   1917 
   1918     def draw_cursor(self, event):

~\anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py in draw(self)
    386         self.renderer = self.get_renderer(cleared=True)
    387         with RendererAgg.lock:
--> 388             self.figure.draw(self.renderer)
    389             # A GUI class may be need to update a window using this draw, so
    390             # don't forget to call the superclass.

~\anaconda3\lib\site-packages\matplotlib\artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
     36                 renderer.start_filter()
     37 
---> 38             return draw(artist, renderer, *args, **kwargs)
     39         finally:
     40             if artist.get_agg_filter() is not None:

~\anaconda3\lib\site-packages\matplotlib\figure.py in draw(self, renderer)
   1707             self.patch.draw(renderer)
   1708             mimage._draw_list_compositing_images(
-> 1709                 renderer, self, artists, self.suppressComposite)
   1710 
   1711             renderer.close_group('figure')

~\anaconda3\lib\site-packages\matplotlib\image.py in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
    133     if not_composite or not has_images:
    134         for a in artists:
--> 135             a.draw(renderer)
    136     else:
    137         # Composite any adjacent images together

~\anaconda3\lib\site-packages\matplotlib\artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
     36                 renderer.start_filter()
     37 
---> 38             return draw(artist, renderer, *args, **kwargs)
     39         finally:
     40             if artist.get_agg_filter() is not None:

~\anaconda3\lib\site-packages\matplotlib\axes\_base.py in draw(self, renderer, inframe)
   2645             renderer.stop_rasterizing()
   2646 
-> 2647         mimage._draw_list_compositing_images(renderer, self, artists)
   2648 
   2649         renderer.close_group('axes')

~\anaconda3\lib\site-packages\matplotlib\image.py in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
    133     if not_composite or not has_images:
    134         for a in artists:
--> 135             a.draw(renderer)
    136     else:
    137         # Composite any adjacent images together

~\anaconda3\lib\site-packages\matplotlib\artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
     36                 renderer.start_filter()
     37 
---> 38             return draw(artist, renderer, *args, **kwargs)
     39         finally:
     40             if artist.get_agg_filter() is not None:

~\anaconda3\lib\site-packages\matplotlib\legend.py in draw(self, renderer)
    656         # update the location and size of the legend. This needs to
    657         # be done in any case to clip the figure right.
--> 658         bbox = self._legend_box.get_window_extent(renderer)
    659         self.legendPatch.set_bounds(bbox.x0, bbox.y0,
    660                                     bbox.width, bbox.height)
~\anaconda3\lib\site-packages\matplotlib\offsetbox.py in get_extent_offsets(self, renderer)
    491 
    492         whd_list = [c.get_extent(renderer)
--> 493                     for c in self.get_visible_children()]
    494 
    495         if not whd_list:

~\anaconda3\lib\site-packages\matplotlib\offsetbox.py in <listcomp>(.0)
    491 
    492         whd_list = [c.get_extent(renderer)
--> 493                     for c in self.get_visible_children()]
    494 
    495         if not whd_list:

~\anaconda3\lib\site-packages\matplotlib\offsetbox.py in get_extent(self, renderer)
    284     def get_extent(self, renderer):
    285         """Return a tuple ``width, height, xdescent, ydescent`` of the box."""
--> 286         w, h, xd, yd, offsets = self.get_extent_offsets(renderer)
    287         return w, h, xd, yd
    288 

~\anaconda3\lib\site-packages\matplotlib\offsetbox.py in get_extent_offsets(self, renderer)
    417 
    418         whd_list = [c.get_extent(renderer)
--> 419                     for c in self.get_visible_children()]
    420         whd_list = [(w, h, xd, (h - yd)) for w, h, xd, yd in whd_list]
    421 

~\anaconda3\lib\site-packages\matplotlib\offsetbox.py in <listcomp>(.0)
    417 
    418         whd_list = [c.get_extent(renderer)
--> 419                     for c in self.get_visible_children()]
    420         whd_list = [(w, h, xd, (h - yd)) for w, h, xd, yd in whd_list]
    421 

~\anaconda3\lib\site-packages\matplotlib\offsetbox.py in get_extent(self, renderer)
    284     def get_extent(self, renderer):
    285         """Return a tuple ``width, height, xdescent, ydescent`` of the box."""
--> 286         w, h, xd, yd, offsets = self.get_extent_offsets(renderer)
    287         return w, h, xd, yd
    288 

~\anaconda3\lib\site-packages\matplotlib\offsetbox.py in get_extent_offsets(self, renderer)
    491 
    492         whd_list = [c.get_extent(renderer)
--> 493                     for c in self.get_visible_children()]
    494 
    495         if not whd_list:

~\anaconda3\lib\site-packages\matplotlib\offsetbox.py in <listcomp>(.0)
    491 
    492         whd_list = [c.get_extent(renderer)
--> 493                     for c in self.get_visible_children()]
    494 
    495         if not whd_list:

~\anaconda3\lib\site-packages\matplotlib\offsetbox.py in get_extent(self, renderer)
    875             "lp", self._text._fontproperties, ismath=False)
    876 
--> 877         bbox, info, d = self._text._get_layout(renderer)
    878         w, h = bbox.width, bbox.height
    879 

~\anaconda3\lib\site-packages\matplotlib\text.py in _get_layout(self, renderer)
    296             if clean_line:
    297                 w, h, d = renderer.get_text_width_height_descent(
--> 298                     clean_line, self._fontproperties, ismath=ismath)
    299             else:
    300                 w = h = d = 0

~\anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py in get_text_width_height_descent(self, s, prop, ismath)
    199             fontsize = prop.get_size_in_points()
    200             w, h, d = texmanager.get_text_width_height_descent(
--> 201                 s, fontsize, renderer=self)
    202             return w, h, d
    203 

~\anaconda3\lib\site-packages\matplotlib\texmanager.py in get_text_width_height_descent(self, tex, fontsize, renderer)
    446         else:
    447             # use dviread. It sometimes returns a wrong descent.
--> 448             dvifile = self.make_dvi(tex, fontsize)
    449             with dviread.Dvi(dvifile, 72 * dpi_fraction) as dvi:
    450                 page, = dvi

~\anaconda3\lib\site-packages\matplotlib\texmanager.py in make_dvi(self, tex, fontsize)
    336                 self._run_checked_subprocess(
    337                     ["latex", "-interaction=nonstopmode", "--halt-on-error",
--> 338                      texfile], tex)
    339             for fname in glob.glob(basefile + '*'):
    340                 if not fname.endswith(('dvi', 'tex')):

~\anaconda3\lib\site-packages\matplotlib\texmanager.py in _run_checked_subprocess(self, command, tex)
    315                     prog=command[0],
    316                     tex=tex.encode('unicode_escape'),
--> 317                     exc=exc.output.decode('utf-8'))) from exc
    318         _log.debug(report)
    319         return report

RuntimeError: latex was not able to process the following string:
b'\\u0441\\u0442\\u0438\\u043b1'

Here is the full report generated by latex:
This is pdfTeX, Version 3.14159265-2.6-1.40.20 (TeX Live 2019/W32TeX) (preloaded format=latex)
 restricted \write18 enabled.
entering extended mode
(c:/Users/Victor/.matplotlib/tex.cache/b6f49bb15be8eba85bb671cfafccfb49.tex
LaTeX2e <2020-02-02> patch level 5
L3 programming layer <2020-02-25>
(c:/texlive/2019/texmf-dist/tex/latex/base/article.cls
Document Class: article 2019/12/20 v1.4l Standard LaTeX document class
(c:/texlive/2019/texmf-dist/tex/latex/base/size10.clo))
(c:/texlive/2019/texmf-dist/tex/latex/type1cm/type1cm.sty)
(c:/texlive/2019/texmf-dist/tex/latex/base/textcomp.sty)
(c:/texlive/2019/texmf-dist/tex/latex/base/inputenc.sty)
(c:/texlive/2019/texmf-dist/tex/latex/geometry/geometry.sty
(c:/texlive/2019/texmf-dist/tex/latex/graphics/keyval.sty)
(c:/texlive/2019/texmf-dist/tex/generic/iftex/ifvtex.sty
(c:/texlive/2019/texmf-dist/tex/generic/iftex/iftex.sty))

Package geometry Warning: Over-specification in `h'-direction.
    `width' (5058.9pt) is ignored.


Package geometry Warning: Over-specification in `v'-direction.
    `height' (5058.9pt) is ignored.

) (c:/texlive/2019/texmf-dist/tex/latex/l3backend/l3backend-dvips.def)
(./b6f49bb15be8eba85bb671cfafccfb49.aux)
*geometry* driver: auto-detecting
*geometry* detected driver: dvips

! Package inputenc Error: Unicode character с (U+0441)
(inputenc)                not set up for use with LaTeX.

See the inputenc package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.14 \fontsize{10.000000}{12.500000}{\sffamily с
                                                 тил1}
No pages of output.
Transcript written on b6f49bb15be8eba85bb671cfafccfb49.log.


---------------------------------------------------------------------------
CalledProcessError                        Traceback (most recent call last)
~\anaconda3\lib\site-packages\matplotlib\texmanager.py in _run_checked_subprocess(self, command, tex)
    303                                              cwd=self.texcache,
--> 304                                              stderr=subprocess.STDOUT)
    305         except FileNotFoundError as exc:

~\anaconda3\lib\subprocess.py in check_output(timeout, *popenargs, **kwargs)
    410     return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
--> 411                **kwargs).stdout
    412 

~\anaconda3\lib\subprocess.py in run(input, capture_output, timeout, check, *popenargs, **kwargs)
    511             raise CalledProcessError(retcode, process.args,
--> 512                                      output=stdout, stderr=stderr)
    513     return CompletedProcess(process.args, retcode, stdout, stderr)

CalledProcessError: Command '['latex', '-interaction=nonstopmode', '--halt-on-error', 'C:\\Users\\Victor\\.matplotlib\\tex.cache\\b6f49bb15be8eba85bb671cfafccfb49.tex']' returned non-zero exit status 1.

The above exception was the direct cause of the following exception:

RuntimeError                              Traceback (most recent call last)
~\anaconda3\lib\site-packages\IPython\core\formatters.py in __call__(self, obj)
    339                 pass
    340             else:
--> 341                 return printer(obj)
    342             # Finally look for special method names
    343             method = get_real_method(obj, self.print_method)

~\anaconda3\lib\site-packages\IPython\core\pylabtools.py in <lambda>(fig)
    246 
    247     if 'png' in formats:
--> 248         png_formatter.for_type(Figure, lambda fig: print_figure(fig, 'png', **kwargs))
    249     if 'retina' in formats or 'png2x' in formats:
    250         png_formatter.for_type(Figure, lambda fig: retina_figure(fig, **kwargs))

~\anaconda3\lib\site-packages\IPython\core\pylabtools.py in print_figure(fig, fmt, bbox_inches, **kwargs)
    130         FigureCanvasBase(fig)
    131 
--> 132     fig.canvas.print_figure(bytes_io, **kw)
    133     data = bytes_io.getvalue()
    134     if fmt == 'svg':

~\anaconda3\lib\site-packages\matplotlib\backend_bases.py in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, bbox_inches, **kwargs)
   2063                         orientation=orientation,
   2064                         dryrun=True,
-> 2065                         **kwargs)
   2066                     renderer = self.figure._cachedRenderer
   2067                     bbox_artists = kwargs.pop("bbox_extra_artists", None)

~\anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py in print_png(self, filename_or_obj, metadata, pil_kwargs, *args, **kwargs)
    525 
    526         else:
--> 527             FigureCanvasAgg.draw(self)
    528             renderer = self.get_renderer()
    529             with cbook._setattr_cm(renderer, dpi=self.figure.dpi), \

~\anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py in draw(self)
    386         self.renderer = self.get_renderer(cleared=True)
    387         with RendererAgg.lock:
--> 388             self.figure.draw(self.renderer)
    389             # A GUI class may be need to update a window using this draw, so
    390             # don't forget to call the superclass.

~\anaconda3\lib\site-packages\matplotlib\artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
     36                 renderer.start_filter()
     37 
---> 38             return draw(artist, renderer, *args, **kwargs)
     39         finally:
     40             if artist.get_agg_filter() is not None:

~\anaconda3\lib\site-packages\matplotlib\figure.py in draw(self, renderer)
   1707             self.patch.draw(renderer)
   1708             mimage._draw_list_compositing_images(
-> 1709                 renderer, self, artists, self.suppressComposite)
   1710 
   1711             renderer.close_group('figure')

~\anaconda3\lib\site-packages\matplotlib\image.py in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
    133     if not_composite or not has_images:
    134         for a in artists:
--> 135             a.draw(renderer)
    136     else:
    137         # Composite any adjacent images together

~\anaconda3\lib\site-packages\matplotlib\artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
     36                 renderer.start_filter()
     37 
---> 38             return draw(artist, renderer, *args, **kwargs)
     39         finally:
     40             if artist.get_agg_filter() is not None:

~\anaconda3\lib\site-packages\matplotlib\axes\_base.py in draw(self, renderer, inframe)
   2645             renderer.stop_rasterizing()
   2646 
-> 2647         mimage._draw_list_compositing_images(renderer, self, artists)
   2648 
   2649         renderer.close_group('axes')

~\anaconda3\lib\site-packages\matplotlib\image.py in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
    133     if not_composite or not has_images:
    134         for a in artists:
--> 135             a.draw(renderer)
    136     else:
    137         # Composite any adjacent images together

~\anaconda3\lib\site-packages\matplotlib\artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
     36                 renderer.start_filter()
     37 
---> 38             return draw(artist, renderer, *args, **kwargs)
     39         finally:
     40             if artist.get_agg_filter() is not None:

~\anaconda3\lib\site-packages\matplotlib\legend.py in draw(self, renderer)
    656         # update the location and size of the legend. This needs to
    657         # be done in any case to clip the figure right.
--> 658         bbox = self._legend_box.get_window_extent(renderer)
    659         self.legendPatch.set_bounds(bbox.x0, bbox.y0,
    660                                     bbox.width, bbox.height)

~\anaconda3\lib\site-packages\matplotlib\offsetbox.py in get_window_extent(self, renderer)
    289     def get_window_extent(self, renderer):
    290         """Return the bounding box (`.Bbox`) in display space."""
--> 291         w, h, xd, yd, offsets = self.get_extent_offsets(renderer)
    292         px, py = self.get_offset(w, h, xd, yd, renderer)
    293         return mtransforms.Bbox.from_bounds(px - xd, py - yd, w, h)

~\anaconda3\lib\site-packages\matplotlib\offsetbox.py in get_extent_offsets(self, renderer)
    417 
    418         whd_list = [c.get_extent(renderer)
--> 419                     for c in self.get_visible_children()]
    420         whd_list = [(w, h, xd, (h - yd)) for w, h, xd, yd in whd_list]
    421 

~\anaconda3\lib\site-packages\matplotlib\offsetbox.py in <listcomp>(.0)
    417 
    418         whd_list = [c.get_extent(renderer)
--> 419                     for c in self.get_visible_children()]
    420         whd_list = [(w, h, xd, (h - yd)) for w, h, xd, yd in whd_list]
    421 

~\anaconda3\lib\site-packages\matplotlib\offsetbox.py in get_extent(self, renderer)
    284     def get_extent(self, renderer):
    285         """Return a tuple ``width, height, xdescent, ydescent`` of the box."""
--> 286         w, h, xd, yd, offsets = self.get_extent_offsets(renderer)
    287         return w, h, xd, yd
    288 

~\anaconda3\lib\site-packages\matplotlib\offsetbox.py in get_extent_offsets(self, renderer)
    491 
    492         whd_list = [c.get_extent(renderer)
--> 493                     for c in self.get_visible_children()]
    494 
    495         if not whd_list:

~\anaconda3\lib\site-packages\matplotlib\offsetbox.py in <listcomp>(.0)
    491 
    492         whd_list = [c.get_extent(renderer)
--> 493                     for c in self.get_visible_children()]
    494 
    495         if not whd_list:

~\anaconda3\lib\site-packages\matplotlib\offsetbox.py in get_extent(self, renderer)
    284     def get_extent(self, renderer):
    285         """Return a tuple ``width, height, xdescent, ydescent`` of the box."""
--> 286         w, h, xd, yd, offsets = self.get_extent_offsets(renderer)
    287         return w, h, xd, yd
    288 

~\anaconda3\lib\site-packages\matplotlib\offsetbox.py in get_extent_offsets(self, renderer)
    417 
    418         whd_list = [c.get_extent(renderer)
--> 419                     for c in self.get_visible_children()]
    420         whd_list = [(w, h, xd, (h - yd)) for w, h, xd, yd in whd_list]
    421 

~\anaconda3\lib\site-packages\matplotlib\offsetbox.py in <listcomp>(.0)
    417 
    418         whd_list = [c.get_extent(renderer)
--> 419                     for c in self.get_visible_children()]
    420         whd_list = [(w, h, xd, (h - yd)) for w, h, xd, yd in whd_list]
    421 

~\anaconda3\lib\site-packages\matplotlib\offsetbox.py in get_extent(self, renderer)
    284     def get_extent(self, renderer):
    285         """Return a tuple ``width, height, xdescent, ydescent`` of the box."""
--> 286         w, h, xd, yd, offsets = self.get_extent_offsets(renderer)
    287         return w, h, xd, yd
    288 

~\anaconda3\lib\site-packages\matplotlib\offsetbox.py in get_extent_offsets(self, renderer)
    491 
    492         whd_list = [c.get_extent(renderer)
--> 493                     for c in self.get_visible_children()]
    494 
    495         if not whd_list:

~\anaconda3\lib\site-packages\matplotlib\offsetbox.py in <listcomp>(.0)
    491 
    492         whd_list = [c.get_extent(renderer)
--> 493                     for c in self.get_visible_children()]
    494 
    495         if not whd_list:

~\anaconda3\lib\site-packages\matplotlib\offsetbox.py in get_extent(self, renderer)
    875             "lp", self._text._fontproperties, ismath=False)
    876 
--> 877         bbox, info, d = self._text._get_layout(renderer)
    878         w, h = bbox.width, bbox.height
    879 

~\anaconda3\lib\site-packages\matplotlib\text.py in _get_layout(self, renderer)
    296             if clean_line:
    297                 w, h, d = renderer.get_text_width_height_descent(
--> 298                     clean_line, self._fontproperties, ismath=ismath)
    299             else:
    300                 w = h = d = 0

~\anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py in get_text_width_height_descent(self, s, prop, ismath)
    199             fontsize = prop.get_size_in_points()
    200             w, h, d = texmanager.get_text_width_height_descent(
--> 201                 s, fontsize, renderer=self)
    202             return w, h, d
    203 

~\anaconda3\lib\site-packages\matplotlib\texmanager.py in get_text_width_height_descent(self, tex, fontsize, renderer)
    446         else:
    447             # use dviread. It sometimes returns a wrong descent.
--> 448             dvifile = self.make_dvi(tex, fontsize)
    449             with dviread.Dvi(dvifile, 72 * dpi_fraction) as dvi:
    450                 page, = dvi

~\anaconda3\lib\site-packages\matplotlib\texmanager.py in make_dvi(self, tex, fontsize)
    336                 self._run_checked_subprocess(
    337                     ["latex", "-interaction=nonstopmode", "--halt-on-error",
--> 338                      texfile], tex)
    339             for fname in glob.glob(basefile + '*'):
    340                 if not fname.endswith(('dvi', 'tex')):

~\anaconda3\lib\site-packages\matplotlib\texmanager.py in _run_checked_subprocess(self, command, tex)
    315                     prog=command[0],
    316                     tex=tex.encode('unicode_escape'),
--> 317                     exc=exc.output.decode('utf-8'))) from exc
    318         _log.debug(report)
    319         return report

RuntimeError: latex was not able to process the following string:
b'\\u0441\\u0442\\u0438\\u043b1'

Here is the full report generated by latex:
This is pdfTeX, Version 3.14159265-2.6-1.40.20 (TeX Live 2019/W32TeX) (preloaded format=latex)
 restricted \write18 enabled.
entering extended mode
(c:/Users/Victor/.matplotlib/tex.cache/b6f49bb15be8eba85bb671cfafccfb49.tex
LaTeX2e <2020-02-02> patch level 5
L3 programming layer <2020-02-25>
(c:/texlive/2019/texmf-dist/tex/latex/base/article.cls
Document Class: article 2019/12/20 v1.4l Standard LaTeX document class
(c:/texlive/2019/texmf-dist/tex/latex/base/size10.clo))
(c:/texlive/2019/texmf-dist/tex/latex/type1cm/type1cm.sty)
(c:/texlive/2019/texmf-dist/tex/latex/base/textcomp.sty)
(c:/texlive/2019/texmf-dist/tex/latex/base/inputenc.sty)
(c:/texlive/2019/texmf-dist/tex/latex/geometry/geometry.sty
(c:/texlive/2019/texmf-dist/tex/latex/graphics/keyval.sty)
(c:/texlive/2019/texmf-dist/tex/generic/iftex/ifvtex.sty
(c:/texlive/2019/texmf-dist/tex/generic/iftex/iftex.sty))

Package geometry Warning: Over-specification in `h'-direction.
    `width' (5058.9pt) is ignored.


Package geometry Warning: Over-specification in `v'-direction.
    `height' (5058.9pt) is ignored.

) (c:/texlive/2019/texmf-dist/tex/latex/l3backend/l3backend-dvips.def)
(./b6f49bb15be8eba85bb671cfafccfb49.aux)
*geometry* driver: auto-detecting
*geometry* detected driver: dvips

! Package inputenc Error: Unicode character с (U+0441)
(inputenc)                not set up for use with LaTeX.

See the inputenc package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.14 \fontsize{10.000000}{12.500000}{\sffamily с
                                                 тил1}
No pages of output.
Transcript written on b6f49bb15be8eba85bb671cfafccfb49.log.
# coding: utf-8

import numpy as np
import matplotlib.pyplot as plt

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

x = np.linspace(-np.pi, np.pi, 256)
y = []
for i in range(-100, 100):
    y += [np.cos(x + i)]


plt.xlim(-10, 10)
plt.ylim(-2, 2)
plt.xticks([-10, 0, 10])
plt.yticks()
plt.plot(x, y[0], color = 'red', linewidth = 2.5, linestyle = '-', label = 'стил1')
plt.plot(x, y[1], color = 'blue', linewidth = 3, linestyle = '-', label = 'style2')
plt.legend()
plt.show()