Where are Matplotlib's default defaults located?
I am looking at the documentation of
matplotlib.pyplot.savefig, and in particular of its
The resolution in dots per inch. If
Noneit will default to the value
savefig.dpiin the matplotlibrc file.
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
matplotlibrc provided by the package is actually the commented out example provided by
My questions are:
- Is this a documentation bug? If we follow the documentation, this is undefined behavior.
- 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
figurein my case), I am asking where those default defaults come from.)
The matplotlib default rcParams are defined in the file
The default for the
savefig.dpiof the current development version is
'savefig.dpi': ['figure', validate_dpi], # DPI(currently line 1298)
'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:
- 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).
The actual values can be found using e.g.
import matplotlib.pyplot as plt print(plt.rcParams)
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.