背景:這裏是一個最低工作的例子,產生錯誤:劃線{}在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