Wrong latex rendering in matplotlib

折月煮酒 提交于 2019-12-23 12:03:42

问题


With python 2.7.12 (on Ubuntu 16.04), and matplotlib 1.5.2, the following code is rendered incorrectly:

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

The xlabel renders as if it was $\partial i\Delta$ and the title renders as if it was $\rightharpoonup\Upsilon\partial$ as you can see here:

My latex installation is otherwise functional. Any idea what the problem is?


回答1:


As you can read in the User's Guide, about the matplotlibrc file:

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

Therefore, you should use a concrete font.family property or just change the text.usetex parameter to True in the matplotlibrc file.

#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


来源:https://stackoverflow.com/questions/39337229/wrong-latex-rendering-in-matplotlib

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!