Как отобразить графики Matplotlib с кодом TEX на кириллице - PullRequest
0 голосов
/ 26 марта 2020

Я пытаюсь понять, как наносить цифры с текстом кириллицы c в легенде.

Кажется, что оси отображают символы 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()

Изменение метки первой (красной) строки на кириллицу c:

plt.plot(x, y[0], color = 'red', linewidth = 2.5, linestyle = '-', label = 'стил1')

дает следующую ошибку:

Ошибка в обратном вызове .post_execute at 0x00000202EDCA3AF8> (для post_execute):

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

Решение этого важно для меня, потому что я планирую повторить все проект, написанный с использованием R (книга) в Python.

1 Ответ

0 голосов
/ 26 марта 2020

Вам нужно сообщить тексу, что вы хотите отобразить немного русского языка.

enter image description here

# 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()
...