Matplotlib中的LaTeX渲染错误

5

使用Python 2.7.12 (在Ubuntu 16.04上),以及matplotlib 1.5.2,以下代码渲染不正确:

from matplotlib.pyplot import *
plot([1,2],[1,1])
xlabel(r"$\beta+1$")
title(r'$\alpha > \beta$')
show()

xlabel的呈现方式就像是$\partial i\Delta$,而title的呈现方式就像是$\rightharpoonup\Upsilon\partial$,可以在这里看到: output

我的latex安装正常运行,有什么问题吗?


1
你应该描述“incorrectly”是什么意思(期望的行为和实际的行为是什么)。 - YakovL
我认为很明显,在这种情况下LaTeX渲染是不正确的。话虽如此,在使用matplotlib 1.5.1的Mint上,结果是正确的(只是为了确保;这意味着例如“beta”实际上被渲染为“beta” ;))。 - Bart
1
在macOS上,使用Python 2.7.11和Matplotlib 1.5.1可以正常工作(Latex正确渲染)。 - cameronroytaylor
在_Arch-Linux_上使用python 2.7.12matplotlib 1.5.2运行良好。 - Ohad Eytan
问题出在matplotlib的rc参数上:由于某种原因,我的matplotlibrc文件中的text.usetex被设置为False。将其改回True即可解决问题。 - tomaok
1个回答

1

正如您可以在用户指南中阅读到的那样,关于matplotlibrc文件:

# [...] When text.usetex is False,
# font.family may also be one or more concrete font names.

因此,您应该使用具体的font.family属性或仅在matplotlibrc文件中将text.usetex参数更改为True
#text.usetex     : False  # use latex for all text handling. The following fonts
                          # are supported through the usual rc parameter settings:
                          # new century schoolbook, bookman, times, palatino,
                          # zapf chancery, charter, serif, sans-serif, helvetica,
                          # avant garde, courier, monospace, computer modern roman,
                          # computer modern sans serif, computer modern typewriter
                          # If another font is desired which can loaded using the
                          # LaTeX \usepackage command, please inquire at the
                          # matplotlib mailing list

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接