0

我正在尝试在 OS X 上的 EPD 7.3-2(64 位)中运行以下示例代码:

import numpy as np
import matplotlib.mlab as mlab
import matplotlib.pyplot as plt
mu, sigma = 100, 15
x = mu + sigma*np.random.randn(10000)
n, bins, patches = plt.hist(x, 50, normed=1, alpha=0.75)
y = mlab.normpdf( bins, mu, sigma)
l = plt.plot(bins, y, 'r--', linewidth=1)
plt.xlabel('Smarts')
plt.ylabel('Probability')
plt.title(r'$\mathrm{Histogram\ of\ IQ:}\ \mu=100,\ \sigma=15$')
plt.axis([40, 160, 0, 0.03])
plt.grid(True)
plt.show()

最后一行给了我一个错误:

RuntimeError:无法打开面部文件/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/mpl-data/fonts/ttf/Vera.ttf;Cannot_Open_Resource

有两点我不明白。首先,那个 Vera.ttf 文件是在指定的位置,所以我不知道为什么 Python 打不开它。

其次,我完全不明白它为什么会出现在那里。我的 EPD matplotlib 安装在 /Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/matplotlib。为什么它不在那里寻找 Vera.ttf?它确实存在于 /Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/matplotlib/mpl-data/fonts/ttf 中。sys.path 中没有列出 2.6 目录,那里只列出了预期的 EPD 2.7 目录。最后,我的PATH环境变量是/Library/Frameworks/EPD64.framework/Versions/Current/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/垃圾桶。

4

1 回答 1

2

这听起来像是 Matplotlib 字体缓存的问题。你能试试这个相关帖子中的建议吗:https ://stackoverflow.com/a/4956933/260303

简而言之,只需删除 config 目录中的字体缓存:rm ~/.matplotlib/fontList.cache.

于 2013-02-25T23:27:39.723 回答