.matplotlibrc 和默认选项 [英] .matplotlibrc and default options
问题描述
我正在研究用于Python的matplotlib库.我开始了解它的一些基本复杂性,如 pylab 和 pyplot 之间的区别,并且我正在尝试复制和修改图库中的一些示例.
I am studying the matplotlib library for Python. I am starting to understand some of its basic intricacies, as the difference between pylab and pyplot, and I am trying to replicate and modify some of the examples in the gallery.
我还不太明白的一件事是配置文件matplotlibrc的实际作用.
One thing that still I don't understand clearly is the actual role of the configuration file 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
At present I use the WinPython 3.3.5.0 64 bit distribution under Windows 7. The .matplotlibrc file is under WinPython-64bit-3.3.5.0\python-3.3.5.amd64\lib\site-packages\matplotlib\mpl-data\matplotlibrc
我想开始更改一些选项,作为默认字体,所以我打开它,发现除了一行(后端:TkAgg)之外的所有行都被注释了.
I want starting to change some options, as the default font, so I opened it, discovering that all the lines, except one (backend : TkAgg) are commented.
所以我想问一下matplotlib从哪里获取所有默认值(例如fonts属性).某处是否有另一个文件,或者它们是否以某种方式在库中硬编码"?谢谢.
So I would like to ask from where matplotlib takes all the default values (e.g. the fonts properties). Is there another file somewhere, or are they in some way "hard-coded" in the library? Thanks.
推荐答案
matplotlibrc
文件是:
Search order:
* current working dir
* environ var MATPLOTLIBRC
* HOME/.matplotlib/matplotlibrc
* MATPLOTLIBDATA/matplotlibrc
如果在这些路径中没有找到文件,则会发出警告:
and if no file is found in these paths a warning is raised:
warnings.warn('Could not find matplotlibrc; using defaults')
matplotlibrc
文件只是对现有默认参数的更新.可以使用以下方法找到它们:
The matplotlibrc
file is just an update to the existing default parameters. These can be found using:
from matplotlib.rcsetup import defaultParams
(这显然在matplotlib/rcsetup.py
)
在 __ init __.py
文件中,matplotlib循环浏览此字典并定义将用于所有脚本和代码的默认rc参数:
In the __init__.py
file, matplotlib cycles through this dictionary and defines the default rc parameter that will be used for all scripts and codes:
rcParamsDefault = RcParams([ (key, default) for key, (default, converter) in \
defaultParams.iteritems() ])
因此,如果您想知道默认值,请查看:
So if you want to know the defaults, look at:
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',
...
这篇关于.matplotlibrc 和默认选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!