Matplotlib没有听取字体选择

Ame*_*ina 6 python matplotlib seaborn

我无法避免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]))
Run Code Online (Sandbox Code Playgroud)

我已经编辑了我的.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
Run Code Online (Sandbox Code Playgroud)

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

mwa*_*kom 5

如果你正在使用seaborn并且没有安装Arial,这将会发生(我实际上目前正在使这项工作更好).暂时的最佳解决方案是打电话

sns.set(font="serif")
Run Code Online (Sandbox Code Playgroud)

进口seaborn之后和绘图之前.