matplotlib rc('text', usetex=True) 产生错误



我在让乳胶渲染与matplotlib一起使用时遇到了问题。我已经遵循了 https://matplotlib.org/users/usetex.html 故障排除部分中提到的所有提示,例如清除.matplotlib/tex.cache并确保一切都在我的Unix路径上,但无济于事。我正在使用Spyder 3.2.8,Texlive 2018,Python 3.6,conda 4.5.4,Ghostscript 9.23和dvipng 1.15。我使用的是运行MacOS 10.13.2的2012 Macbook Pro。下面是一个最小的工作示例。

import logging
logging.basicConfig(level=logging.DEBUG)
import matplotlib.pyplot as plt
import numpy as np
plt.close("all")
plt.rc('text', usetex=True)
x=np.arange(1,10)
plt.plot(x,x)

这会产生压倒性的误差输出

DEBUG:matplotlib.texmanager:serif font is not compatible with usetex.
INFO:matplotlib.texmanager:No LaTeX-compatible font found for the serif font family in rcParams. Using default.
DEBUG:matplotlib.texmanager:sans-serif font is not compatible with usetex.
DEBUG:matplotlib.texmanager:sans-serif font is not compatible with usetex.
DEBUG:matplotlib.texmanager:family: sans-serif, font: Computer Modern Sans Serif, info: ('cmss', '')
DEBUG:matplotlib.texmanager:cursive font is not compatible with usetex.
DEBUG:matplotlib.texmanager:cursive font is not compatible with usetex.
DEBUG:matplotlib.texmanager:family: cursive, font: Zapf Chancery, info: ('pzc', '\usepackage{chancery}')
DEBUG:matplotlib.texmanager:monospace font is not compatible with usetex.
DEBUG:matplotlib.texmanager:monospace font is not compatible with usetex.
DEBUG:matplotlib.texmanager:family: monospace, font: Computer Modern Typewriter, info: ('cmtt', '')
DEBUG:matplotlib.texmanager:following keys changed: ['text.latex.preamble', 'font.family', 'font.serif', 'font.sans-serif', 'font.cursive', 'font.monospace']
DEBUG:matplotlib.texmanager:text.latex.preamble : None       -> []        
DEBUG:matplotlib.texmanager:font.family         : None       -> ['serif'] 
DEBUG:matplotlib.texmanager:font.serif          : None       -> ['Times New Roman']
DEBUG:matplotlib.texmanager:font.sans-serif     : None       -> ['DejaVu Sans', 'Bitstream Vera Sans', 'Computer Modern Sans Serif', 'Lucida Grande', 'Verdana', 'Geneva', 'Lucid', 'Arial', 'Helvetica', 'Avant Garde', 'sans-serif']
DEBUG:matplotlib.texmanager:font.cursive        : None       -> ['Apple Chancery', 'Textile', 'Zapf Chancery', 'Sand', 'Script MT', 'Felipa', 'cursive']
DEBUG:matplotlib.texmanager:font.monospace      : None       -> ['DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Computer Modern Typewriter', 'Andale Mono', 'Nimbus Mono L', 'Courier New', 'Courier', 'Fixed', 'Terminal', 'monospace']
DEBUG:matplotlib.texmanager:RE-INIT
old fontconfig: serifcmrcmsspzccmttd41d8cd98f00b204e9800998ecf8427e
DEBUG:matplotlib.texmanager:serif font is not compatible with usetex.
INFO:matplotlib.texmanager:No LaTeX-compatible font found for the serif font family in rcParams. Using default.
DEBUG:matplotlib.texmanager:sans-serif font is not compatible with usetex.
DEBUG:matplotlib.texmanager:sans-serif font is not compatible with usetex.
DEBUG:matplotlib.texmanager:family: sans-serif, font: Computer Modern Sans Serif, info: ('cmss', '')
DEBUG:matplotlib.texmanager:cursive font is not compatible with usetex.
DEBUG:matplotlib.texmanager:cursive font is not compatible with usetex.
DEBUG:matplotlib.texmanager:family: cursive, font: Zapf Chancery, info: ('pzc', '\usepackage{chancery}')
DEBUG:matplotlib.texmanager:monospace font is not compatible with usetex.
DEBUG:matplotlib.texmanager:monospace font is not compatible with usetex.
DEBUG:matplotlib.texmanager:family: monospace, font: Computer Modern Typewriter, info: ('cmtt', '')
DEBUG:matplotlib.texmanager:fontconfig: serifcmrcmsspzccmttd41d8cd98f00b204e9800998ecf8427e
DEBUG:matplotlib.texmanager:fontconfig: serifcmrcmsspzccmttd41d8cd98f00b204e9800998ecf8427e
DEBUG:matplotlib.texmanager:['latex', '-interaction=nonstopmode', '--halt-on-error', '/Users/Ewan/.matplotlib/tex.cache/c63236ff577e7f75eb3a0878a3cae5b8.tex']
Traceback (most recent call last):
File "/Users/Ewan/anaconda3/lib/python3.6/site-packages/matplotlib/backends/backend_qt5.py", line 519, in _draw_idle
self.draw()
File "/Users/Ewan/anaconda3/lib/python3.6/site-packages/matplotlib/backends/backend_agg.py", line 433, in draw
self.figure.draw(self.renderer)
File "/Users/Ewan/anaconda3/lib/python3.6/site-packages/matplotlib/artist.py", line 55, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "/Users/Ewan/anaconda3/lib/python3.6/site-packages/matplotlib/figure.py", line 1475, in draw
renderer, self, artists, self.suppressComposite)
File "/Users/Ewan/anaconda3/lib/python3.6/site-packages/matplotlib/image.py", line 141, in _draw_list_compositing_images
a.draw(renderer)
File "/Users/Ewan/anaconda3/lib/python3.6/site-packages/matplotlib/artist.py", line 55, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "/Users/Ewan/anaconda3/lib/python3.6/site-packages/matplotlib/axes/_base.py", line 2607, in draw
mimage._draw_list_compositing_images(renderer, self, artists)
File "/Users/Ewan/anaconda3/lib/python3.6/site-packages/matplotlib/image.py", line 141, in _draw_list_compositing_images
a.draw(renderer)
File "/Users/Ewan/anaconda3/lib/python3.6/site-packages/matplotlib/artist.py", line 55, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "/Users/Ewan/anaconda3/lib/python3.6/site-packages/matplotlib/axis.py", line 1192, in draw
renderer)
File "/Users/Ewan/anaconda3/lib/python3.6/site-packages/matplotlib/axis.py", line 1130, in _get_tick_bboxes
extent = tick.label1.get_window_extent(renderer)
File "/Users/Ewan/anaconda3/lib/python3.6/site-packages/matplotlib/text.py", line 922, in get_window_extent
bbox, info, descent = self._get_layout(self._renderer)
File "/Users/Ewan/anaconda3/lib/python3.6/site-packages/matplotlib/text.py", line 309, in _get_layout
ismath=ismath)
File "/Users/Ewan/anaconda3/lib/python3.6/site-packages/matplotlib/backends/backend_agg.py", line 232, in get_text_width_height_descent
s, fontsize, renderer=self)
File "/Users/Ewan/anaconda3/lib/python3.6/site-packages/matplotlib/texmanager.py", line 501, in get_text_width_height_descent
dvifile = self.make_dvi(tex, fontsize)
File "/Users/Ewan/anaconda3/lib/python3.6/site-packages/matplotlib/texmanager.py", line 365, in make_dvi
texfile], tex)
File "/Users/Ewan/anaconda3/lib/python3.6/site-packages/matplotlib/texmanager.py", line 335, in _run_checked_subprocess
stderr=subprocess.STDOUT)
File "/Users/Ewan/anaconda3/lib/python3.6/subprocess.py", line 336, in check_output
**kwargs).stdout
File "/Users/Ewan/anaconda3/lib/python3.6/subprocess.py", line 403, in run
with Popen(*popenargs, **kwargs) as process:
File "/Users/Ewan/anaconda3/lib/python3.6/subprocess.py", line 709, in __init__
restore_signals, start_new_session)
File "/Users/Ewan/anaconda3/lib/python3.6/subprocess.py", line 1344, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'latex': 'latex'

编辑1:从命令行调用时,相同的代码运行良好,甚至可以在以下情况下正确呈现乳胶

plt.xlabel("$int_0^1 sin(\alpha)$")
plt.show()

附加到上述示例的末尾。因此,问题出在Spyder吗?Spyder即使在我的PATH上也找不到Latex吗?

我在MacOS X 4.4.0上的jupyter notebook 10.13.6中遇到了同样的问题。这些错误仅在我自己开始使用日志记录模块时才出现。

最新更新