【问题标题】:Matplotlib not listening to font choicesMatplotlib 不听字体选择
【发布时间】:2014-06-06 02:45:39
【问题描述】:

我无法避免 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。

【问题讨论】:

  • 添加了 seaborn 标签。如果你没有使用直接的 matplotlib,你应该指出你正在使用什么扩展层。

标签: python matplotlib seaborn


【解决方案1】:

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

sns.set(font="serif")

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

【讨论】:

  • 谢谢 -- 从那以后有解决方案吗?我最近从 master 升级了 seaborn,但没有成功。
  • 不幸的是,我最终将问题归结为 matplotlib 中的一个错误。它应该在 1.4 中修复...
  • 什么是sns?如果在我的系统上可用,我将如何设置 Arial?
  • Seaborn 最常作为 sns 导入。
【解决方案2】:

来自the documentation (see method description for set_family or set_name)

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

如果您想使用 TeX,或许应该使用“serif”、“sans-serif”、“cursive”、“fantasy”或“monospace”等字体系列。

【讨论】:

  • 谢谢,虽然我不确定我是否遵循。我在哪里没有像你提到的那样指定字体系列?我究竟需要在我的.matplotlibrc 中更改什么?
  • 查看您指定“Arial”的代码会很有帮助。
  • 我不是自己设置的。我想知道这是否来自导入seaborn
  • seaborn 确实覆盖了字体。 @user815423426
猜你喜欢
  • 1970-01-01
  • 2011-11-29
  • 1970-01-01
  • 2017-07-04
  • 1970-01-01
  • 1970-01-01
  • 2017-10-06
  • 2017-06-25
相关资源
最近更新 更多