Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
701 views
in Technique[技术] by (71.8m points)

python - .matplotlibrc and default options

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.

One thing that still I don't understand clearly is the actual role of the configuration file 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.0python-3.3.5.amd64libsite-packagesmatplotlibmpl-datamatplotlibrc

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.

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Judging from the documentation and the code in matplotlib\__init__.py in the site packages directory you can see that the search path for the matplotlibrc file is:

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')

The matplotlibrc file is just an update to the existing default parameters. These can be found using:

from matplotlib.rcsetup import defaultParams

(this is obviously in matplotlib/rcsetup.py)

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',
 ...

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...