[英]matplotlib mathtext can't find fonts
我试图弄清楚如何使mathtext在python matplotlib中工作。
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]))
/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无法正确呈现。 该图如下所示:
何时应如下所示:
显然,这是旧版本的matplotlib(我的fedora存储库中的版本)存在的错误。 我下载并安装了最新版本,并修复了该错误。
为了获得最新版本,我必须从源代码构建它。 按照matplotlib 安装说明页面上的说明 ,
首先,获取构建依赖项: sudo yum-builddep python-matplotlib
然后,从下载页面获取最新的.tar.gz(撰写本文时为1.2版)
然后,其余部分由python安装脚本处理。
cd matplotlib // wherever the .tar.gz was extracted to.
python setup.py build
python setup.py install
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.