[英]matplotlib rc('text', usetex=True) producing errors
I'm having trouble getting latex rendering to work with matplotlib. 我无法让乳胶渲染与matplotlib一起使用。 I've followed all the tips mentioned in the troubleshooting section of https://matplotlib.org/users/usetex.html , such as clearing .matplotlib/tex.cache
and ensuring everything is on my Unix path, but to no avail. 我已经按照https://matplotlib.org/users/usetex.html的故障排除部分中提到的所有提示进行了操作,例如清除.matplotlib/tex.cache
并确保一切都在我的Unix路径上,但无济于事。 I'm using Spyder 3.2.8, Texlive 2018, Python 3.6, conda 4.5.4, Ghostscript 9.23 and dvipng 1.15. 我正在使用Spyder 3.2.8,Texlive 2018,Python 3.6,conda 4.5.4,Ghostscript 9.23和dvipng 1.15。 I'm using a 2012 Macbook Pro running MacOS 10.13.2. 我正在使用运行MacOS 10.13.2的2012 Macbook Pro。 Below is a minimal working example. 下面是一个最小的工作示例。
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)
This produces the overwhelming error output 这会产生压倒性的错误输出
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'
EDIT 1: The same code runs fine when called from the command line, and even renders latex correctly when 编辑1:从命令行调用时,相同的代码运行正常,甚至在正确时渲染乳胶
plt.xlabel("$\int_0^1 \sin(\\alpha)$")
plt.show()
is appended to the end of the example above. 附加到上面示例的末尾。 Is the problem therefore Spyder? 因此Spyder的问题是什么? Can Spyder fail to find Latex even when its on my PATH? Spyder即使在我的PATH上也无法找到Latex?
I'm encountering the same problem in jupyter notebook 4.4.0 on MacOS X 10.13.6. 我在MacOS X 10.13.6上的jupyter笔记本4.4.0中遇到了同样的问题。 The errors only showed up when I started using the logging module myself. 当我开始自己使用日志记录模块时,错误才会出现。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.