2013-03-01 96 views
1

我想弄清楚如何获得在python matplotlib中工作的mathtext。matplotlib mathtext找不到字体

他们提供一些small example code我所抄录如下:

import numpy as np 
import matplotlib.pyplot as plt 
t = np.arange(0.0, 2.0, 0.01) 
s = np.sin(2*np.pi*t) 

plt.plot(t,s) 
plt.title(r'$\alpha_i > \beta_i$', fontsize=20) 
plt.text(1, -0.6, r'$\sum_{i=0}^\infty x_i$', fontsize=20) 
plt.text(0.6, 0.6, r'$\mathcal{A}\mathrm{sin}(2 \omega t)$', 
    fontsize=20) 
plt.xlabel('time (s)') 
plt.ylabel('volts (mV)') 
plt.show() 

当我尝试运行这段代码,我得到很多的警告看起来像这样: /usr/lib/python2.7/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]))

和mathtext没有按” t正确渲染。这个数字看起来是这样的:

Figure with broken fonts

当它应该是这样的:

how figure should look

+0

尝试清除matplotlib'd字体缓存 – 2013-03-01 01:12:44

+0

什么是你的系统和python的版本和matplotlib你使用? – 2013-03-01 08:12:17

+0

@DavidZwicker fedora 14,python 2.7,python-matplotlib-1.0.1-12.fc14.i686 – Joe 2013-03-01 22:13:37

回答

0

显然,这是与旧版本matplotlib的错误,那是在我的Fedora版本库。我下载并安装了最新版本,并修复了这个错误。

要获得最新版本,我必须从源代码构建它。从matplotlib installation instructions page

首先,让构建依赖以下的说明: sudo yum-builddep python-matplotlib

然后,从download page(在写作时的版本1.2)

获得最新的名为.tar.gz然后,其余的由一个python安装脚本来处理。

cd matplotlib // wherever the .tar.gz was extracted to. 
python setup.py build 
python setup.py install