首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >matplotlib rc('text',usetex=True)产生错误

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

Stack Overflow用户
提问于 2018-06-16 07:51:14
回答 1查看 2.8K关注 0票数 3

在matplotlib中使用latex渲染时遇到了问题。我遵循了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。下面是一个最小的工作示例。

代码语言:javascript
运行
AI代码解释
复制
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)

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

代码语言:javascript
运行
AI代码解释
复制
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:当从命令行调用时,相同的代码运行良好,甚至可以正确地呈现latex

代码语言:javascript
运行
AI代码解释
复制
plt.xlabel("$\int_0^1 \sin(\\alpha)$")
plt.show()

追加到上述示例的末尾。那么Spyder就是问题所在吗?Spyder即使在我的路径上也能找不到Latex吗?

EN

回答 1

Stack Overflow用户

发布于 2018-07-15 11:54:18

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50886030

复制
相关文章
Matplotlib 中文用户指南 4.7 使用 LaTeX 渲染文本
Matplotlib 可以选择使用 LaTeX 来管理所有文本布局。 此选项可用于以下后端:
ApacheCN_飞龙
2022/12/01
4K0
Matplotlib 中文用户指南 4.7 使用 LaTeX 渲染文本
Matplotlib 可视化之注释与文本高级应用
可以使用scipy.special.jn()函数,其中需要计算整数阶贝塞尔函数 Jn 的零点,可以使用函数 scipy.special.jn_zeros(n, nt)
数据STUDIO
2022/05/24
1.4K0
Matplotlib 可视化之注释与文本高级应用
Matplotlib 中文用户指南 4.8 XeLaTeX/LuaLaTeX 设置
使用 pgf 后端,matplotlib 可以将图形导出为可以使用 pdflatex,xelatex 或 lualatex 处理的 pgf 绘图命令。 XeLaTeX 和 LuaLaTeX 具有完整的 unicode 支持,可以使用安装在操作系统中的任何字体,利用 OpenType,AAT 和 Graphite 的高级排版功能。 由plt.savefig('figure.pgf')创建的 Pgf 图片可以作为原始命令嵌入到 LaTeX 文档中。 图形也可以通过切换到该后端,直接编译并使用plt.savefig('figure.pdf')保存到 PDF。
ApacheCN_飞龙
2022/12/01
1.6K0
Matplotlib 中文用户指南 4.8 XeLaTeX/LuaLaTeX 设置
matplotlib基础手册:pyplot手册
matplotlib.pyplot 是一个函数集合,使 matplotlib 能够像 MATLAB 一样进行绘图。每一个 pyplot 函数都会改变 figure,比如创建figure,在figure中创建绘图区域,在绘图区域绘制线条,添加 labels 等。matplotlib.pyplot 的函数调用会记住当前的状态,从而更新 figure 和 绘图区域。而且 matplotlib.pyplot 是直接在当前 axes 进行绘图。
bugsuse
2020/04/21
2.7K0
matplotlib基础手册:pyplot手册
基于可视化理论的清晰Python图表
实际上,本文介绍了能从经典的《定量信息的视觉展示(The Visual Display of Quantitative Information)》(Edward Tufte)中学到的大部分知识,以及如何在Python中实现它。
人工智能小咖
2020/05/03
2.1K0
基于可视化理论的清晰Python图表
Matplotlib 中文用户指南 4.6 编写数学表达式
你可以在任何 matplotlib 文本字符串中使用子 TeX 标记,将它放在一对美元符号($)内。
ApacheCN_飞龙
2022/12/01
1.6K0
Matplotlib 中文用户指南 4.6 编写数学表达式
错误 RC1015: 无法打开包含文件 'XTToolkitPro.rc'
XtremeToolkitPro作为VC++/MFC平台下目前最流行的GUI界面库之一,安装和使用都很方便。不过,在实际使用中还是碰到许多问题。如果在编译工程时只显示一个错误:RC1015: 无法打开包含文件 'XTToolkitPro.rc',这时可能是因为资源路径问题导致。解决方法有两种:
步行者08
2018/10/09
2.4K0
气象绘图——复杂的三维图
在普通的matplotlib的三维投影中,我们似乎并不能获得我们想要的结果,尤其是视觉上的,虽然倾斜了图形,但是文字等标注仍然是二维的,例如下面这张图片:
自学气象人
2023/06/21
1.2K0
气象绘图——复杂的三维图
Fielddata is disabled on text fields by default. Set fielddata=true on [Tag] in order to load field
这是要开启fielddate 可以执行 PUT /索引/_mapping/类型 { "properties": { "出问题的字段": { "type": "text", "fielddata": true } } } 在postman什么的执行的时候记得body得改为json,否则会失败
全栈程序员站长
2021/04/07
6810
python matplotlib 安装 和错误处理
首先我参考是:http://www.cnblogs.com/lifegoesonitself/p/3443866.html
全栈程序员站长
2022/06/28
8730
python matplotlib 安装 和错误处理
使用C++ Builder 6编译产生错误
作者:Gandalf1024 链接:https://www.jianshu.com/p/f42d045d5014 來源:简书 简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。
战神伽罗
2019/07/24
1.1K0
解决Sublime Text 3:there are no packages available for installation错误
我们在使用Sublime Text 3 进行编程的时候会使用Package Control安装一些常用的插件帮助我们进行编程 有时候我们在安装插件时会遇到这种报错的情况:
用户2475223
2019/12/17
1.9K0
解决Sublime Text 3:there are no packages available for installation错误
解决matplotlib中的Invalid DISPLAY variable错误
其实这是因为matplotlib是默认画图backend是TkAgg,这个需要有GUI的图形界面。只需要指定不需要GUI的backend就可以解决这个问题:
生信编程日常
2021/07/27
1.6K0
非阻塞情况下connect产生EINPROGRESS错误[通俗易懂]
//原文地址:http://blog.csdn.net/saspss/article/details/8487678
全栈程序员站长
2022/09/09
1.3K0
Python绘制3D色温球
对于二维数组的球坐标色温展示效果,现有教程不尽人意,如何按照数组中数值的大小赋予颜色值,下文通过函数定义方式,一步到位达到绘制目的。
梁佐佐
2021/09/08
1.1K0
【Python环境】matplotlib - 2D 与 3D 图的绘制
类MATLAB API 最简单的入门是从类 MATLAB API 开始,它被设计成兼容 MATLAB 绘图函数。 让我们加载它: from pylab import * 使用 qt 作为图形后端: %matplotlib qt 示例 类MATLAB API 绘图的简单例子: from numpy import * x = linspace(0, 5, 10) y = x ** 2figure() plot(x, y, 'r') xlabel('x') ylabel('y') title('title') s
陆勤_数据人网
2018/02/27
5.7K0
【Python环境】matplotlib - 2D 与 3D 图的绘制
错误使用 C++ 模板特化产生的坑
答案是:链接方式 1 产生的 main 输出 specialization,链接方式 2 产生的 main 输出 normal。
zhiruili
2023/10/20
4530
2022-09-30:以下go语言代码输出什么?A: true true false true false; B: true false false true
2022-09-30:以下go语言代码输出什么?A: true true false true false; B: true false false true false; C: true true true false false;D: true true false true true。
福大大架构师每日一题
2022/09/30
1.3K0
2022-09-30:以下go语言代码输出什么?A: true true false true false; B: true false false true
点击加载更多

相似问题

matplotlib - savefig与usetex=True

10

Matplotlib在text.usetex==True时不使用latex字体

30

libpng错误:设置usetex=True后使用matplotlib时读取错误

12

matplotlib无法输出带有usetex = True的EPS图形

12

使用'text.usetex‘= true时,pdf中嵌入的字体错误

12
添加站长 进交流群

领取专属 10元无门槛券

AI混元助手 在线答疑

扫码加入开发者社群
关注 腾讯云开发者公众号

洞察 腾讯核心技术

剖析业界实践案例

扫码关注腾讯云开发者公众号
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档