【问题标题】:Matplotlib Error: LaTeX was not able to process the following string: 'lp'Matplotlib 错误:LaTeX 无法处理以下字符串:'lp'
【发布时间】:2015-09-21 17:34:59
【问题描述】:

这是我从底部提供的函数中得到的错误:

'latex' is not recognized as an internal or external command,
operable program or batch file.
Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\python27\lib\lib-tk\Tkinter.py", line 1486, in __call__
    return self.func(*args)
  File "C:\python27\lib\site-packages\matplotlib\backends\backend_tkagg.py", lin
e 278, in resize
    self.show()
  File "C:\python27\lib\site-packages\matplotlib\backends\backend_tkagg.py", lin
e 349, in draw
    FigureCanvasAgg.draw(self)
  File "C:\python27\lib\site-packages\matplotlib\backends\backend_agg.py", line
469, in draw
    self.figure.draw(self.renderer)
  File "C:\python27\lib\site-packages\matplotlib\artist.py", line 59, in draw_wr
apper
    draw(artist, renderer, *args, **kwargs)
  File "C:\python27\lib\site-packages\matplotlib\figure.py", line 1079, in draw
    func(*args)
  File "C:\python27\lib\site-packages\matplotlib\artist.py", line 59, in draw_wr
apper
    draw(artist, renderer, *args, **kwargs)
  File "C:\python27\lib\site-packages\matplotlib\axes\_base.py", line 2092, in d
raw
    a.draw(renderer)
  File "C:\python27\lib\site-packages\matplotlib\artist.py", line 59, in draw_wr
apper
    draw(artist, renderer, *args, **kwargs)
  File "C:\python27\lib\site-packages\matplotlib\axis.py", line 1116, in draw
    renderer)
  File "C:\python27\lib\site-packages\matplotlib\axis.py", line 1065, in _get_ti
ck_bboxes
    extent = tick.label1.get_window_extent(renderer)
  File "C:\python27\lib\site-packages\matplotlib\text.py", line 741, in get_wind
ow_extent
    bbox, info, descent = self._get_layout(self._renderer)
  File "C:\python27\lib\site-packages\matplotlib\text.py", line 311, in _get_lay
out
    ismath=False)
  File "C:\python27\lib\site-packages\matplotlib\backends\backend_agg.py", line
223, in get_text_width_height_descent
    renderer=self)
  File "C:\python27\lib\site-packages\matplotlib\texmanager.py", line 670, in ge
t_text_width_height_descent
    dvifile = self.make_dvi(tex, fontsize)
  File "C:\python27\lib\site-packages\matplotlib\texmanager.py", line 417, in ma
ke_dvi
    report))
RuntimeError: LaTeX was not able to process the following string:
'lp'
Here is the full report generated by LaTeX:

这是我正在使用的导致上述错误的函数:

def Derivative( inputArrayList,rowNumber_from_top ):
    for image in inputArrayList:
        rowValues = image[0][rowNumber_from_top]
        for i in range(len(rowValues)):         
            # Perform the difference derivative estimation
            if i == 0 or i == (len(rowValues) - 1):
                rowValues[ i ] = 0 # set edges to 0
            else:
                derivative = (rowValues[ i+1 ] - rowValues[ i-1 ])/(2.0)
                rowValues[ i ] = derivative
        plt.rc('text', usetex=True)
        plt.rc('font', family='serif')
        plt.plot(rowValues,color="k")
        plt.ylim( (0,image.max() + 10.0) )
        plt.title(r"$\displaystyle\sum_{n=1}^\infty\frac{-e^{i\pi}}{2^n}$")
        plt.show()

注意plt.title(r"$\displaystyle\sum_{n=1}^\infty\frac{-e^{i\pi}}{2^n}$") 这一行。我从 Matplotlib 网站上的 first graph 获取了这个(我也尝试过运行他们提供的那个程序),但我似乎无法让它工作。我几乎可以肯定这是一个简单的修复(比如我可能缺少 LaTeX 模块或其他东西?)。

整个目标是能够在情节的标题和标签中使用命令\displaystyle 来增大分数。

如果这是重复的,我深表歉意(尽管我找不到类似的问题),我只需要一个指针来让我朝着正确的方向前进。

感谢您的宝贵时间,

布兰登

【问题讨论】:

  • “这是 LaTeX 生成的完整报告:”之后是否有任何内容?你也可以看看这是否有帮助:stackoverflow.com/questions/11354149/…
  • @AmyTeegarden 不幸的是,不,在“这是 LaTeX 生成的完整报告:”之后,它是空白的。感谢您的链接!我去看看type1cm。
  • 你可以直接在 LaTeX 中处理该行,而不是通过 matplotlib 运行吗?如果它不调用\displaystyle,你能处理它吗?可以运行使用 LaTeX 的 Matplotlib 库示例代码吗?
  • 有人找到答案了吗?我有同样的问题。已尝试安装相关软件包和大量谷歌搜索。
  • @WadeBratz 我认为这是解决方案:stackoverflow.com/a/11357765/3928184

标签: python python-2.7 matplotlib


【解决方案1】:

您似乎缺少用于 dvi 渲染的包。在基于 debian 的发行版上,这应该足以获得所有需要的软件包:

sudo apt-get install texlive-latex-extra texlive-fonts-recommended dvipng cm-super

【讨论】:

  • 关于 mac 的任何想法?
  • 对于较新版本的 Matplotlib,还需要安装 cm-super sudo apt-get install cm-super
  • 如果有人在 MacOSX 上遇到同样的问题,我更新了所有 tex 包(通过转到作为 MacTeX 一部分的 Tex Live Utility 应用程序 --> 更新选项卡 --> 全选 --> 右键单击和更新),这似乎已经解决了它。我无法确定哪个包是问题所在,但至少我认为知道更新所有内容可以解决问题是件好事。
【解决方案2】:

你应该测试你是否安装了乳胶。为此,打开一个终端并输入

which latex

输出应该是你的 Latex 二进制文件的路径。如果没有找到,尝试安装一个 Latex 发行版。这个过程取决于你的操作系统,例如 Ubuntu 有几个包。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多