【问题标题】:Google Colab: How to use LateX fonts in matplotlib?Google Colab:如何在 matplotlib 中使用 LateX 字体?
【发布时间】:2022-11-13 13:59:56
【问题描述】:

按照here的建议,我想我可以包含以下代码片段来在 matplotlib 中呈现乳胶字体

plt.rcParams.update({
    "text.usetex": True,
    "font.family": "Computer Modern Roman"
})

为了确保安装了乳胶,我还运行了!pip install latex。我在 Windows 11 上运行 Google Colab。

然而,这是我收到的错误:

RuntimeError: latex was not able to process the following string:
b'lp'

Here is the full report generated by latex:
This is pdfTeX, Version 3.14159265-2.6-1.40.18 (TeX Live 2017/Debian) (preloaded format=latex)
 restricted \write18 enabled.
entering extended mode
(/root/.cache/matplotlib/tex.cache/41e3affc34550e765935caf5a875fad6.tex
LaTeX2e <2017-04-15>
Babel <3.18> and hyphenation patterns for 3 language(s) loaded.
(/usr/share/texlive/texmf-dist/tex/latex/base/article.cls
Document Class: article 2014/09/29 v1.4h Standard LaTeX document class
(/usr/share/texlive/texmf-dist/tex/latex/base/size10.clo))
(/usr/share/texlive/texmf-dist/tex/latex/type1cm/type1cm.sty)

! LaTeX Error: File `type1ec.sty' not found.

Type X to quit or <RETURN> to proceed,
or enter new name. (Default extension: sty)

Enter file name: 
! Emergency stop.
<read *> 
         
l.6 \usepackage
               {type1ec}^^M
No pages of output.
Transcript written on 41e3affc34550e765935caf5a875fad6.log.

任何帮助将不胜感激。

【问题讨论】:

    标签: python matplotlib google-colaboratory


    【解决方案1】:

    在 Google colab 中运行此代码,它会工作

    plt.rcParams['mathtext.fontset'] = 'cm'
    plt.rcParams['font.family'] = 'STIXGeneral'
    
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-03-09
      • 2016-02-29
      • 1970-01-01
      • 2011-02-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-01
      相关资源
      最近更新 更多