背景:这是产生错误的最小工作示例:
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
最佳答案
我尝试了你的代码片段,它似乎对我有用。
这就是你想要实现的目标吗?
python 版本:2.7
matplotlib 版本:1.3.1。
关于python - Matplotlib 中的\overline{} 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28374345/