微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

将“contour”包包含到 matlplotlib 中并使用它设置标题

如何解决将“contour”包包含到 matlplotlib 中并使用它设置标题

在 matplotlib 脚本中,我尝试使用 Latex 样式编写文本,尤其是通过使用 contour 包在每个字母和数字上添加黑色轮廓(字母为黄色,因此难以阅读)。

为此,我在脚本开始时做了:

from matplotlib import rcParams
rcParams['text.usetex'] = True
rcParams['text.latex.preamble'] = [r'\usepackage{contour}']

当我需要设置标题时:

ax.set_title(r'$\contour{black}{\color{yellow}\bm{1 \sigma} \pm '+str(min_majorx)+'}$',fontsize=18)

我收到以下错误

    exc=exc.output.decode('utf-8'))) from exc
RuntimeError: latex was not able to process the following string:
b'$\\\\contour{black}{\\\\color{yellow}\\\\bm{1 \\\\sigma} \\\\pm 0.0265}$'

Here is the full report generated by latex:
This is pdfTeX,Version 3.14159265-2.6-1.40.21 (TeX Live 2020/MacPorts 2020.54632_3) (preloaded format=latex)
 restricted \write18 enabled.
entering extended mode
(/Users/fab/.matplotlib/tex.cache/b4389630837c80060f94471e39c4ace7.tex
LaTeX2e <2020-02-02> patch level 5
L3 programming layer <2020-03-06>
(/opt/local/share/texmf-texlive/tex/latex/base/article.cls
Document Class: article 2019/12/20 v1.4l Standard LaTeX document class
(/opt/local/share/texmf-texlive/tex/latex/base/size10.clo))
(/opt/local/share/texmf-texlive/tex/latex/type1cm/type1cm.sty)
(/opt/local/share/texmf-texlive/tex/latex/base/textcomp.sty)
(/opt/local/share/texmf-texlive/tex/latex/base/inputenc.sty)
(/opt/local/share/texmf-texlive/tex/latex/tools/bm.sty)
(/opt/local/share/texmf-texlive/tex/latex/geometry/geometry.sty
(/opt/local/share/texmf-texlive/tex/latex/graphics/keyval.sty)
(/opt/local/share/texmf-texlive/tex/generic/iftex/ifvtex.sty
(/opt/local/share/texmf-texlive/tex/generic/iftex/iftex.sty))

Package geometry Warning: Over-specification in `h'-direction.
    `width' (5058.9pt) is ignored.


Package geometry Warning: Over-specification in `v'-direction.
    `height' (5058.9pt) is ignored.

) (/opt/local/share/texmf-texlive/tex/latex/l3backend/l3backend-dvips.def)
(./b4389630837c80060f94471e39c4ace7.aux)
*geometry* driver: auto-detecting
*geometry* detected driver: dvips
! Undefined control sequence.
<recently read> \contour

l.14 ...{18.000000}{22.500000}{\sffamily $\contour
                                                  {black}{\color{yellow}\bm{...

所以,我尝试做不同的事情:

ax.set_title(r'$\contour{black}{\bm{1 \sigma} \pm '+str(min_majorx)+'}$',fontsize=18,color='yellow')

但总是一个错误

    exc=exc.output.decode('utf-8'))) from exc
RuntimeError: latex was not able to process the following string:
b'$\\\\contour{black}{\\\\bm{1 \\\\sigma} \\\\pm 0.0265}$'

Here is the full report generated by latex:
This is pdfTeX,Version 3.14159265-2.6-1.40.21 (TeX Live 2020/MacPorts 2020.54632_3) (preloaded format=latex)
 restricted \write18 enabled.
entering extended mode
(/Users/fab/.matplotlib/tex.cache/f05a774af393af47b8fb85610c6d84aa.tex
LaTeX2e <2020-02-02> patch level 5
L3 programming layer <2020-03-06>
(/opt/local/share/texmf-texlive/tex/latex/base/article.cls
Document Class: article 2019/12/20 v1.4l Standard LaTeX document class
(/opt/local/share/texmf-texlive/tex/latex/base/size10.clo))
(/opt/local/share/texmf-texlive/tex/latex/type1cm/type1cm.sty)
(/opt/local/share/texmf-texlive/tex/latex/base/textcomp.sty)
(/opt/local/share/texmf-texlive/tex/latex/base/inputenc.sty)
(/opt/local/share/texmf-texlive/tex/latex/tools/bm.sty)
(/opt/local/share/texmf-texlive/tex/latex/geometry/geometry.sty
(/opt/local/share/texmf-texlive/tex/latex/graphics/keyval.sty)
(/opt/local/share/texmf-texlive/tex/generic/iftex/ifvtex.sty
(/opt/local/share/texmf-texlive/tex/generic/iftex/iftex.sty))

Package geometry Warning: Over-specification in `h'-direction.
    `width' (5058.9pt) is ignored.


Package geometry Warning: Over-specification in `v'-direction.
    `height' (5058.9pt) is ignored.

) (/opt/local/share/texmf-texlive/tex/latex/l3backend/l3backend-dvips.def)
(./f05a774af393af47b8fb85610c6d84aa.aux)
*geometry* driver: auto-detecting
*geometry* detected driver: dvips
! Undefined control sequence.
<recently read> \contour

l.14 ...{18.000000}{22.500000}{\sffamily $\contour
                                                  {black}{\bm{1 \sigma} \pm ...

谁能看出哪里出了问题?我是否正确安装了 Latex 包“轮廓”?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。