.matplotlibrc和默认选项

2024-06-01 02:50:15 发布

您现在位置:Python中文网/ 问答频道 /正文

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

我仍然不清楚的是配置文件matplotlibrc的实际作用。

目前我使用的是Windows7下的WinPython3.3.5.0 64位发行版。 .matplotlibrc文件位于WinPython-64bit-3.3.5.0\python-3.3.5.amd64\lib\site packages\matplotlib\mpl data\matplotlibrc下

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

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


Tags: 文件matplotlib配置文件字体画廊amd64例子复杂性
1条回答
网友
1楼 · 发布于 2024-06-01 02:50:15

从site packages目录中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',
 ...

相关问题 更多 >