我正在尝试将matplotlib字体更改为helvetica,我想在PDF图中使用它。我尝试以下方法:无法在Mac OS X上使用Python在Matplotlib中更改Helvetica的字体10.6
import matplotlib
matplotlib.use('PDF')
import matplotlib.pylab as plt
from matplotlib import rc
plt.rcParams['ps.useafm'] = True
rc('font',**{'family':'sans-serif','sans-serif':['Helvetica']})
plt.rcParams['pdf.fonttype'] = 42
这不工作 - 当我跑我的--verbose调试代码,我得到的错误:
backend WXAgg version 2.8.10.1
/Library/Frameworks/Python.framework/Versions/6.2/lib/python2.6/site-packages/matplotlib/__init__.py:833: UserWarning: This call to matplotlib.use() has no effect
because the the backend has already been chosen;
matplotlib.use() must be called *before* pylab, matplotlib.pyplot,
or matplotlib.backends is imported for the first time.
findfont: Could not match :family=sans-serif:style=normal:variant=normal:weight=normal:stretch=normal:size=medium. Returning /Library/Frameworks/Python.framework/Versions/6.2/lib/python2.6/site-packages/matplotlib/mpl-data/fonts/ttf/Vera.ttf
Assigning font /F1 = /Library/Frameworks/Python.framework/Versions/6.2/lib/python2.6/site-packages/matplotlib/mpl-data/fonts/ttf/Vera.ttf
Embedding font /Library/Frameworks/Python.framework/Versions/6.2/lib/python2.6/site-packages/matplotlib/mpl-data/fonts/ttf/Vera.ttf
Writing TrueType font
因此很明显,它不能找到Helvetica字体。我不知道为什么。我有黑体在MPL-数据的AFM目录,并在matplotlib启动读取它和输出:
createFontDict: /Library/Frameworks/Python.framework/Versions/6.2/lib/python2.6/site-packages/matplotlib/mpl-data/fonts/afm/Helvetica.afm
我需要在另外一个特殊的.ttf Helvetica字体?如果是这样,我怎么能得到它?我知道我的系统上有Helvetica,因为我在Illustrator和许多其他程序中看到它。
我使用Enthought Python发布如下:
$ python
Enthought Python Distribution -- http://www.enthought.com
Version: 6.2-2 (32-bit)
Python 2.6.5 |EPD 6.2-2 (32-bit)| (r265:79063, May 28 2010, 15:13:03)
[GCC 4.0.1 (Apple Inc. build 5488)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib
>>> matplotlib.__version__
'0.99.3'
任何想法,这可怎么固定?
谢谢。
感谢您提出问题并回答问题 - 我确信这会对我有所帮助,而这正是StackOverflow的创建目的。 – ShreevatsaR 2010-07-04 22:18:44
你能提供更多的细节吗? Max Malysh的分步解决方案就像一个魅力! – meduz 2016-04-21 10:55:32