gpt4 book ai didi

python - .matplotlibrc 和默认选项

转载 作者:太空宇宙 更新时间:2023-11-03 15:13:41 30 4
gpt4 key购买 nike

我正在研究 Python 的 matplotlib 库。我开始理解它的一些基本复杂性,例如 pylab 和 pyplot 之间的区别,并且我正在尝试复制和修改图库中的一些示例。

有一件事我还没有弄清楚,就是配置文件matplotlibrc的实际作用。

目前我在Windows 7下使用WinPython 3.3.5.0 64位发行版。.matplotlibrc文件在WinPython-64bit-3.3.5.0\python-3.3.5.amd64\lib\site-packages\matplotlib\mpl-data\matplotlibrc下

我想开始更改一些选项,作为默认字体,所以我打开它,发现除了一行(后端:TkAgg)之外的所有行都被注释了。

所以我想问一下 matplotlib 从哪里获取所有默认值(例如字体属性)。某处是否有另一个文件,或者它们是否以某种方式“硬编码”在库中?谢谢。

最佳答案

从站点包目录下matplotlib\__init__.py中的文档和代码可以看出,matplotlibrc文件的搜索路径为:

Search order:                                                                                                                             

* current working dir
* environ var MATPLOTLIBRC
* HOME/.matplotlib/matplotlibrc
* MATPLOTLIBDATA/matplotlibrc

如果在这些路径中没有找到文件,则会发出警告:

warnings.warn('Could not find matplotlibrc; using defaults')

matplotlibrc 文件只是对现有默认参数的更新。这些可以通过以下方式找到:

from matplotlib.rcsetup import defaultParams

(这显然在 matplotlib/rcsetup.py 中)

__init__.py 文件中,matplotlib 循环遍历这个字典并定义将用于所有脚本和代码的默认 rc 参数:

rcParamsDefault = RcParams([ (key, default) for key, (default, converter) in \
defaultParams.iteritems() ])

因此,如果您想了解默认值,请查看:

In [4]: import matplotlib

In [5]: matplotlib.rcParamsDefault
Out[5]:
{'agg.path.chunksize': 0,
'animation.bitrate': -1,
'animation.codec': 'mpeg4',
'animation.ffmpeg_args': '',
'animation.ffmpeg_path': 'ffmpeg',
'animation.frame_format': 'png',
'animation.mencoder_args': '',
'animation.mencoder_path': 'mencoder',
'animation.writer': 'ffmpeg',
...

关于python - .matplotlibrc 和默认选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23483857/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com