Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Option for disregarding matplotlibrc, for reproducible batch production of plots #1819

khinsen opened this Issue Mar 11, 2013 · 7 comments


None yet
5 participants

khinsen commented Mar 11, 2013

I'd like to use matplotlib to generate plots in a reproducible research workflow, meaning that I need to ensure that the same Python script generates exactly the same plot (SVG or PDF), no matter in what environment it runs. In particular, this means I want matplotlib not to read any matplotlibrc other than its default version.

Since matplotlibrc is read upon the initial import of matplotlib, such a feature would have to be implemented by providing a differently names module that does some magic and then imports matplotlib. It doesn't look difficult, and I am willing to to this myself, but I'd like to see comments from more experienced matplotlib hackers first.


mdboom commented Mar 11, 2013

You can simply do:

import matplotlib
# ...and then set any non-default parameters you want...

khinsen commented Mar 12, 2013

That still reads matplotlibrc and then sets the parameters back to their defaults. The parameters from matplotlibrc are still around and could be used later with rc_file_defaults().

My situation is in fact a bit more complicated: I want to integrate matplotlib into a workflow management system in such a way that /any/ user-provided plotting script is reproducible, even if it happens to call rc_file_defaults for whatever reason. Moreover, the system tracks file accesses and issues a warning when matplotlib reads .matplotlibrc. I'd like to get rid of those warnings as well. So I really want matplotlib not to look at that file at all.

BTW, there are more issues like that, in particular with fontList.cache, but I'll worry about them one by one.


tacaswell commented Mar 12, 2013

monkey patch matplotlib.rc_file_defaults = lambda : None ?

khinsen commented Mar 14, 2013

That's a nice workaround, thanks!

My current workaround for the warning message is pre-importing matplotlib before running anything in restricted mode. Matplotlib reads .matplotlibrc only once, so subsequent imports are fine.

@khinsen khinsen closed this Mar 14, 2013


dmcdougall commented Mar 23, 2013

@khinsen You bring up an excellent point here. Actually, as a shameless plug, I just submitted a tutorial proposal for the SciPy 2013 conference at the end of June. I aim to partially solve this problem, as I have had the same issues you have had with reproducing identical plots. As a scientist producing plots for various journals and talks, I like to have a reproducible style that can be reused time and time again that also conforms to journal-specific printing constraints. I can let you know some more details offline if you're interested.


pelson commented Mar 25, 2013

Actually, as a shameless plug, I just submitted a tutorial proposal for the SciPy 2013 conference at the end of June.

Ooo. Sounds interesting. I've pencilled this one in 😄


mdboom commented Mar 25, 2013

Yes! Very interesting...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment