This recipe explains where the various configuration files are that matplotlib uses and why we want to use one or the other. Also, we explain what is in these configuration files.
If you don't want to configure matplotlib as the first step in your code every time you use it (as we did in the previous recipe), this recipe will explain how to have different default configurations of matplotlib for different projects. This way your code will not be cluttered with configuration data and, moreover, you can easily share configuration templates with your co-workers or even among other projects.
If you have a working project that always uses the same settings for certain parameters in matplotlib, you probably don't want to set them every time you want to add a new graph code. Instead, what you want is a permanent file, outside of your code, which sets defaults for matplotlib parameters.
matplotlib supports this via its matplotlibrc
configuration file that contains most of the changeable properties of matplotlib.
There are three different places where this file can reside and its location defines its usage. They are:
matplotlibrc
.$HOME
directory (under Windows
, this is your Documents and Settings
directory). You can find out where your configuration directory is using the matplotlib.get_configdir()
command. Check the next command.The following one liner will print the location of your configuration directory and can be run from shell:
$ python -c 'import matplotlib as mpl; print mpl.get_configdir()'
The configuration file contains settings for:
TkAgg
and GTKAgg
.If you are interested in more details for every mentioned setting (and some that we did not mention here), the best place to go is the website of the matplotlib project where there is up-to-date API documentation. If it doesn't help, user and development lists are always good places to leave questions. See the back of this book for useful online resources.