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.0\python-3.3.5.amd64\lib\site-packages\matplotlib\mpl-data\matplotlibrc
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.
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',
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With