Tidak dapat menggunakan lateks di plot python - RuntimeError: LaTeX tidak dapat memproses string berikut: b'lp'

Saya ingin menggunakan lateks untuk label gambar tetapi saya mendapatkan kesalahan
RuntimeError: LaTeX tidak dapat memproses string berikut: b'lp'
Berikut adalah laporan lengkap yang dihasilkan oleh LaTeX: < br/> dan itu saja (saya tidak melihat laporan apa pun)

Sunting : Inilah seluruh kesalahan yang saya peroleh:

Traceback (most recent call last):
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\backends\backend_qt5agg.py", line 197, in __draw_idle_agg
    FigureCanvasAgg.draw(self)
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py", line 464, in draw
    self.figure.draw(self.renderer)
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\artist.py", line 63, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\figure.py", line 1144, in draw
    renderer, self, dsu, self.suppressComposite)
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\image.py", line 139, in _draw_list_compositing_images
    a.draw(renderer)
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\artist.py", line 63, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\axes\_base.py", line 2426, in draw
    mimage._draw_list_compositing_images(renderer, self, dsu)
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\image.py", line 139, in _draw_list_compositing_images
    a.draw(renderer)
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\artist.py", line 63, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\axis.py", line 1138, in draw
    renderer)
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\axis.py", line 1078, in _get_tick_bboxes
    extent = tick.label1.get_window_extent(renderer)
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\text.py", line 967, in get_window_extent
    bbox, info, descent = self._get_layout(self._renderer)
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\text.py", line 353, in _get_layout
    ismath=False)
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py", line 230, in get_text_width_height_descent
    renderer=self)
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\texmanager.py", line 676, in get_text_width_height_descent
    dvifile = self.make_dvi(tex, fontsize)
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\texmanager.py", line 423, in make_dvi
    report))
RuntimeError: LaTeX was not able to process the following string:
b'lp'
Here is the full report generated by LaTeX: 

Ini kode saya:

import numpy as np
from matplotlib import rc
import matplotlib.pyplot as plt
plt.close('all')

rc('text', usetex = True)

mu = np.linspace(0,10,100)
eta = mu**2

fig, ax = plt.subplots()
ax.plot(mu,eta,label= r'$\eta (\mu)$')
ax.set_title('Test')
ax.legend()
  • Saya menginstal MiKTeX, menambahkannya ke variabel lingkungan sesuai dengan https://docs.alfresco.com/4.2/tasks/fot-addpath.html.
  • Saya memeriksa paket MiKTeX, di mana saya menemukan "miktex-dvipng-bin-x64-2.9" di kategori "\MiKTeX excecutables". Saya menyimpulkan saya punya dvipng.
  • Saya mengunduh Ghostcript, yang juga saya tambahkan ke variabel lingkungan.
  • Saya mencoba mengkompilasi skrip lateks ke pdf menggunakan texworks, dan berfungsi dengan baik, dari apa yang saya simpulkan, LaTeX diinstal dengan benar.
  • Dari https://matplotlib.org/1.4.1/users/usetex.html, hanya ini yang seharusnya saya perlukan...
  • Saya mencoba menghapus direktori .matplotlib/tex.cache saya
  • Saya mencoba menulis
import matplotlib as mpl
mpl.rcParams['text.usetex']=True

alih-alih

from matplotlib import rc
rc('text', usetex = True)

tapi hasilnya sama.

  • Beralih
rc('text', usetex = True)

to

rc('text', usetex = False)

mencegah kesalahan, tetapi label saya tidak ditulis dengan lateks...

Setelah banyak googling, saya kekurangan ide. Adakah yang bisa membantu saya?

Konfigurasi saya adalah:
- Python 3.6 (Saya menjalankan kode saya di spyder)
- MiKTeX 2.9
- Ghostscript 9.50
- Windows 10
- Edit : matplotlib 2.0. 2

Sunting: memutakhirkan ke matplotlib 3.1.1, saya mendapatkan kesalahan berikut:

Traceback (most recent call last):
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\texmanager.py", line 304, in _run_checked_subprocess
    stderr=subprocess.STDOUT)
  File "C:\Users\Vincent\Anaconda3\lib\subprocess.py", line 336, in check_output
    **kwargs).stdout
  File "C:\Users\Vincent\Anaconda3\lib\subprocess.py", line 403, in run
    with Popen(*popenargs, **kwargs) as process:
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 209, in __init__
    super(SubprocessPopen, self).__init__(*args, **kwargs)
  File "C:\Users\Vincent\Anaconda3\lib\subprocess.py", line 707, in __init__
    restore_signals, start_new_session)
  File "C:\Users\Vincent\Anaconda3\lib\subprocess.py", line 992, in _execute_child
    startupinfo)
FileNotFoundError: [WinError 2] Le fichier spécifié est introuvable

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

Traceback (most recent call last):
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\backends\backend_qt5.py", line 505, in _draw_idle
    self.draw()
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py", line 388, in draw
    self.figure.draw(self.renderer)
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\artist.py", line 38, in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\figure.py", line 1709, in draw
    renderer, self, artists, self.suppressComposite)
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\image.py", line 135, in _draw_list_compositing_images
    a.draw(renderer)
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\artist.py", line 38, in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\axes\_base.py", line 2607, in draw
    self._update_title_position(renderer)
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\axes\_base.py", line 2556, in _update_title_position
    if title.get_window_extent(renderer).ymin < top:
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\text.py", line 890, in get_window_extent
    bbox, info, descent = self._get_layout(self._renderer)
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\text.py", line 291, in _get_layout
    ismath="TeX" if self.get_usetex() else False)
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py", line 201, in get_text_width_height_descent
    s, fontsize, renderer=self)
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\texmanager.py", line 448, in get_text_width_height_descent
    dvifile = self.make_dvi(tex, fontsize)
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\texmanager.py", line 338, in make_dvi
    texfile], tex)
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\texmanager.py", line 308, in _run_checked_subprocess
    'found'.format(command[0])) from exc
RuntimeError: Failed to process string with tex because latex could not be found
Traceback (most recent call last):
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\texmanager.py", line 304, in _run_checked_subprocess
    stderr=subprocess.STDOUT)
  File "C:\Users\Vincent\Anaconda3\lib\subprocess.py", line 336, in check_output
    **kwargs).stdout
  File "C:\Users\Vincent\Anaconda3\lib\subprocess.py", line 403, in run
    with Popen(*popenargs, **kwargs) as process:
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 209, in __init__
    super(SubprocessPopen, self).__init__(*args, **kwargs)
  File "C:\Users\Vincent\Anaconda3\lib\subprocess.py", line 707, in __init__
    restore_signals, start_new_session)
  File "C:\Users\Vincent\Anaconda3\lib\subprocess.py", line 992, in _execute_child
    startupinfo)
FileNotFoundError: [WinError 2] Le fichier spécifié est introuvable

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

Traceback (most recent call last):
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\backends\backend_qt5.py", line 505, in _draw_idle
    self.draw()
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py", line 388, in draw
    self.figure.draw(self.renderer)
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\artist.py", line 38, in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\figure.py", line 1709, in draw
    renderer, self, artists, self.suppressComposite)
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\image.py", line 135, in _draw_list_compositing_images
    a.draw(renderer)
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\artist.py", line 38, in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\axes\_base.py", line 2607, in draw
    self._update_title_position(renderer)
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\axes\_base.py", line 2556, in _update_title_position
    if title.get_window_extent(renderer).ymin < top:
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\text.py", line 890, in get_window_extent
    bbox, info, descent = self._get_layout(self._renderer)
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\text.py", line 291, in _get_layout
    ismath="TeX" if self.get_usetex() else False)
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py", line 201, in get_text_width_height_descent
    s, fontsize, renderer=self)
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\texmanager.py", line 448, in get_text_width_height_descent
    dvifile = self.make_dvi(tex, fontsize)
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\texmanager.py", line 338, in make_dvi
    texfile], tex)
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\texmanager.py", line 308, in _run_checked_subprocess
    'found'.format(command[0])) from exc
RuntimeError: Failed to process string with tex because latex could not be found

person Vincent mahé    schedule 05.11.2019    source sumber
comment
Seharusnya ada lebih dari satu baris kesalahan? Bisakah Anda menunjukkan secara lengkap?   -  person ImportanceOfBeingErnest    schedule 05.11.2019
comment
Terima kasih untuk balasan Anda. Saya mengedit pertanyaan saya untuk menunjukkan seluruh kesalahan yang saya peroleh. Selain itu, saya terus mencari masalah saya di Google dan mempelajari tentang backend matplotlib. Saya tidak paham dengan hal ini, tahukah Anda jika ini bisa menjadi asal mula masalah saya?   -  person Vincent mahé    schedule 05.11.2019
comment
Tidak, ini tidak ada hubungannya dengan backend. Ini tentang instalasi lateks Anda. Tetapi jika kesalahan yang dikembalikan lateks hanyalah string kosong, saya khawatir saya tidak tahu apa sebenarnya masalahnya.   -  person ImportanceOfBeingErnest    schedule 05.11.2019
comment
Matplotlib versi berapa? Anda mengutip instruksi dari dua versi utama yang lalu.   -  person Jody Klymak    schedule 05.11.2019
comment
Versi matplotlib saya adalah 2.0.2   -  person Vincent mahé    schedule 06.11.2019
comment
Saya memutakhirkan ke matplotlib 3.1.1 dan saya mendapatkan kesalahan berbeda yang sepertinya menunjukkan saya tidak punya lateks... Saya menulis edit di akhir pertanyaan awal saya untuk menunjukkan kepada Anda seluruh kesalahan   -  person Vincent mahé    schedule 06.11.2019


Jawaban (1)


Untuk ke 5 kalinya saya unistall dan install ulang MikTeX, dan kali ini masalah saya teratasi. Saat menjalankan skrip python saya, tiga jendela terbuka berturut-turut meminta instalasi paket. Jawaban ini saya lampirkan screenshot dari ketiga jendela ini. Setelah menerima untuk menginstal paket-paket ini, skrip saya berfungsi dengan baik. Sebelumnya, ketika unistall dan install ulang MikTeX, saya sudah melihat windows meminta instalasi dan menerima instalasi. Saya tidak tahu mengapa kali ini berhasil padahal sebelumnya tidak berhasil... Bagaimanapun, masalah saya telah terpecahkan dengan menghapus dan menginstal ulang MiKTeX, menjalankan skrip saya dan menerima paket.

Jendela untuk instalasi file dari type1cm

Jendela untuk instalasi file dari iftex

Jendela untuk instalasi file dari zhmetrics

person Vincent mahé    schedule 18.11.2019