背景:这里是一个最低工作的例子,产生错误:划线{}在Matplotlib不工作
from matplotlib import pyplot as plt
plt.plot([0,1,2],[0,1,2],label=r"$\alpha$")
plt.plot([0,1,2],[0,1,2],label=r"$\overline{a}$") #This is the offending line
plt.legend(loc='best')
plt.show()
运行此产生以下错误消息后一个相当长的Traceback
名单:
pyparsing.ParseFatalException: Expected end of math '$'
$\overline{a}$ (at char 0), (line:1, col:1)
我也得到了这个警告,我不知道是否与我的问题有关,因为它是否会在我的脚本中包含“违规行”:
/usr/lib64/python2.6/site-packages/matplotlib/font_manager.py:1242: UserWarning: findfont: Font family ['cmb10'] not found. Falling back to Bitstream Vera Sans (prop.get_family(), self.defaultFamily[fontext]))
/usr/lib64/python2.6/site-packages/matplotlib/font_manager.py:1252: UserWarning: findfont: Could not match :family=Bitstream Vera Sans:style=normal:variant=normal:weight=normal:stretch=normal:size=12. Returning /usr/share/fonts/un-core/UnDotum.ttf UserWarning)
/usr/lib64/python2.6/site-packages/matplotlib/font_manager.py:1242: UserWarning: findfont: Font family ['cmtt10'] not found. Falling back to Bitstream Vera Sans (prop.get_family(), self.defaultFamily[fontext]))
/usr/lib64/python2.6/site-packages/matplotlib/font_manager.py:1242: UserWarning: findfont: Font family ['cmss10'] not found. Falling back to Bitstream Vera Sans (prop.get_family(), self.defaultFamily[fontext]))
如果我不包括“违规行”,因为我已经指定它在上面,那么一切正常。我尝试了各种各样的东西,这些东西让我断定问题集中在\overline{}
左右。但是,我不知道为什么它不起作用,因为documentation表示\overline{}
应该在$$
之内工作。
以前我用plt.rc('text',usetex=True)
来解决这个问题,但现在我正在研究包括在出版物中的情节,我正在调整字体大小和样式以获得最佳可读性,并使用plt.rc('text',usetex=True)
强制我的刻度标签使用默认的LaTeX字体而不是我想要使用的字体。
Python版本:2.6.6
对于它的价值,试试'\ bar {a}'。 – Werner 2015-02-06 20:42:09
虽然有效,但看起来不太好。酒吧并不集中在结束的信件上。 – Joshua 2015-02-06 20:46:57
你使用哪个版本的matplotlib?在我的机器上使用matplotlib v1.4,它工作正常。 – Jakob 2015-02-06 20:55:42