Where are Matplotlib's default defaults located?

I am looking at the documentation of matplotlib.pyplot.savefig, and in particular of its dpi argument:

The resolution in dots per inch. If None it will default to the value savefig.dpi in the matplotlibrc file.

Now regarding matplotlibrc, the documentation gives a list of four locations where it is looked for: only the last one (provided by the package) is applicable to me, which is confirmed by a call to matplotlib.matplotlib_fname().

However, the matplotlibrc provided by the package is actually the commented out example provided by matplotlib.

My questions are:

  1. Is this a documentation bug? If we follow the documentation, this is undefined behavior.
  2. Where are the "default defaults" defined? Is this in yet another file somewhere, or hardcoded within the library? (I know that I can check matplotlib.rcParams['savefig.dpi'] to get its default default value (it is figure in my case), I am asking where those default defaults come from.)

1 answer

  • answered 2017-06-17 19:47 ImportanceOfBeingErnest

    The matplotlib default rcParams are defined in the file rcsetup.py.

    The default for the savefig.dpi of the current development version is

    'savefig.dpi': ['figure', validate_dpi], # DPI (currently line 1298)

    where 'figure' means that the dpi of the figure should be used. The value of the figure dpi defaults to

    'figure.dpi': [100, validate_float], # DPI (currently line 1277)

    Note however two things:

    1. Those values are overwritten in case the matplotlib rc file specifies them (i.e. the respective line in the rc file is not commented out).
    2. The actual values can be found using e.g.

      import matplotlib.pyplot as plt

      Those may already differ from the default values. As an example, the Jupyter notebook sets the default dpi to 72:
      enter image description here

    Concerning the first question, even though the values are commented out in the matplotlibrc, they should be the same as in the rcsetup.py. So either the value is commented out, then they still default to the values in the rc file, or they are not commented out, in which the statement is also obviously correct.