小编ben*_*nzl的帖子

Ubuntu 中 matplotlibrc 中导入 Open Sans 字体失败

我尝试导入Open Sans字体:

import matplotlib as mpl
#update matplotlibrc
mpl.rcParams['font.family'] = 'Open Sans'

#testplot
import matplotlib.pyplot as plt
plt.plot(range(10))
plt.title('Everything is crazy!!!', size=32)
plt.show()
Run Code Online (Sandbox Code Playgroud)

如果我想绘图,matplotlib 找不到字体,给出如下错误消息:

/usr/lib/pymodules/python2.7/matplotlib/font_manager.py:1236: UserWarning: findfont: Font family ['Open Sans'] not found. Falling back to Bitstream Vera Sans
      (prop.get_family(), self.defaultFamily[fontext]))

/usr/lib/pymodules/python2.7/matplotlib/font_manager.py:1246: UserWarning: findfont: Could not match :family=Bitstream Vera Sans:style=normal:variant=normal:weight=light:stretch=normal:size=medium. Returning /usr/share/matplotlib/mpl-data/fonts/ttf/cmb10.ttf
      UserWarning)
Run Code Online (Sandbox Code Playgroud)

该字体安装在 Ubuntu 中,所有 OpenSans-*.ttf 文件也被复制到 matplotlib 文件夹(Ubuntu 中的 /usr/share/matplotlib/mpl-data/fonts/ttf/ )。知道如何使用 matplotlibrc 中的字体吗?

python ubuntu fonts matplotlib

5
推荐指数
1
解决办法
2475
查看次数

标签 统计

fonts ×1

matplotlib ×1

python ×1

ubuntu ×1