7

我无法避免 matplotlib 中关于字体选择的错误。每当我尝试在 Linux 中的远程机器上绘图时,我都会收到以下错误:

/home/josh/anaconda/envs/py27/lib/python2.7/site-packages/matplotlib/font_manager.py:1236:
UserWarning: findfont: Font family ['Arial'] not found. 
Falling back to Bitstream Vera Sans 
(prop.get_family(), self.defaultFamily[fontext]))

我已经编辑了我的.matplotlibrc文件(以防万一,在两个位置):

  • .matplotlib/.matplotlibrc
  • .config/matplotlib/.matplotlibrc

我在其中添加了以下几行:

backend: Agg
font.family        : serif
font.serif         : Times, Palatino, New Century Schoolbook, Bookman, Computer Modern Roman
font.sans-serif    : Helvetica, Avant Garde, Computer Modern Sans serif
font.cursive       : Zapf Chancery
font.monospace     : Courier, Computer Modern Typewriter
text.usetex        : true

不过,matplotlib一直在抱怨Arial。为什么?(请注意,这是在使用 运行脚本时python my_script.py)不涉及 IPython。

4

2 回答 2

6

如果您使用的是 seaborn 并且没有安装 Arial,则会发生这种情况(我实际上目前正在改进这项工作)。暂时最好的解决方案是打电话

sns.set(font="serif")

在导入 seaborn 之后和绘图之前。

于 2014-04-22T20:34:12.297 回答
2

来自文档(请参阅set_familyor的方法描述set_name

当 text.usetex 为 True 时,不支持真实字体名称。

如果您希望能够使用 TeX,也许您应该使用像“serif”、“sans-serif”、“cursive”、“fantasy”或“monospace”这样的字体系列。

于 2014-04-21T23:36:01.867 回答