【问题标题】:matplotlib cannot find configuration file matplotlibrcmatplotlib 找不到配置文件 matplotlibrc
【发布时间】:2015-05-18 09:19:58
【问题描述】:

我在 Ubuntu 14.04 上使用 matplotlib 1.3.1 和 python 3.4.0。我想在.config/matplotlib/matplotlibrc 中使用matplotlibrc configuration file。但是似乎 matplotlib 无法找到它:

~$ ls ~/.config/matplotlib/
matplotlibrc
~$ python3
Python 3.4.0 (default, Apr 11 2014, 13:05:11) 
[GCC 4.8.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib
/usr/lib/python3/dist-packages/matplotlib/__init__.py:766: UserWarning: Could not find matplotlibrc; using defaults
  warnings.warn('Could not find matplotlibrc; using defaults')
/usr/lib/python3/dist-packages/matplotlib/__init__.py:882: UserWarning: could not find rc file; returning defaults
  warnings.warn(message)

matplotlibrc的内容是here的默认内容。

如何让matplotlib找到配置文件?

编辑:

>>> matplotlib.get_configdir()
'/home/<me>/.matplotlib'

【问题讨论】:

  • 你从matplotlib.get_configdir()得到什么?
  • 你有正确的权限来阅读~/.config/matplotlib/matplotlibrc吗? chmod u+rwx ~/.config/matplotlibchmod u+r ~/.config/matplotlib/matplotlibrc 可能会有所帮助。
  • @Marius 查看我对问题的编辑。
  • 好的,所以看起来您应该将 matplotlibrc 文件放在 ~/.matplotlib 而不是 ~/.config/matplotlib 中。不知道为什么配置路径会改变。
  • @Marius 但是当我这样做时,我会收到消息UserWarning: Found matplotlib configuration in ~/.matplotlib/. To conform with the XDG base directory standard, this configuration location has been deprecated on Linux, and the new location is now '/home/me/.config'/matplotlib/. Please move your configuration there to ensure that matplotlib will continue to find it in the future. 所以我想使用正确的位置,或者至少摆脱警告。

标签: python python-3.x matplotlib configuration


【解决方案1】:

我在这里找到了我的,而无需删除 .matplotlib 目录

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/matplotlib/mpl-data/matplotlibrc

【讨论】:

    【解决方案2】:

    matplotlib.get_configdir() 的文档字符串中我发现如果.matplotlib/ 存在,matplotlib 将不会在~/.config 中查找。

    所以即使~/.config/matplotlib/matplotlibrc 存在,你也应该完全删除~/.matplotlib 目录。

    请注意,之后我还必须delete matplotlib's fontcache

    【讨论】:

      猜你喜欢
      • 2023-03-22
      • 2015-09-27
      • 1970-01-01
      • 1970-01-01
      • 2014-10-18
      • 2018-01-01
      • 2014-12-30
      • 2018-01-04
      • 2014-11-17
      相关资源
      最近更新 更多