Configurator¶
- class Configurator(local=True, user=True, default=True, **kwargs)[source]¶
Bases:
collections.abc.MutableMapping,dictA dictionary-like class for managing matplotlib settings stored in
rc_matplotliband ProPlot settings stored inrc_proplot. This class is instantiated as thercobject on import. See the user guide for details.- Parameters
local (
bool, optional) – Whether to load settings from thelocal_filesfile. Default isTrue.user (
bool, optional) – Whether to load settings from theuser_filefile. Default isTrue.default (
bool, optional) – Whether to reload built-in default ProPlot settings. Default isTrue.
Attributes Summary
A dictionary of settings that have been changed from the ProPlot defaults.
Methods Summary
category(cat, *[, trimcat, context])Return a dictionary of settings beginning with the substring
cat + '.'.context(*args[, mode, file])Temporarily modify the rc settings in a "with as" block.
fill(props, *[, context])Return a dictionary filled with settings whose names match the string values in the input dictionary.
find(key, *[, context])Return a single setting.
load(path)Load settings from the specified file.
load_file(*[, new_obj, message])Return locations of local proplotrc files in this directory and in parent directories.
reset([local, user, default])Reset the configurator to its initial state.
save([path, user, comment, backup, description])Save the current settings to a
proplotrcfile.update(*args, **kwargs)Update several settings at once.
Return location of the default proplotrc file.
user_folder([subfolder])Return location of the default proplot folder.
Attributes Documentation
- changed¶
A dictionary of settings that have been changed from the ProPlot defaults.
Methods Documentation
- category(cat, *, trimcat=True, context=False)[source]¶
Return a dictionary of settings beginning with the substring
cat + '.'. Optionally limit the search to the context level.- Parameters
See also
- context(*args, mode=0, file=None, **kwargs)[source]¶
Temporarily modify the rc settings in a “with as” block.
- Parameters
- Other Parameters
mode (
{0, 1, 2}, optional) – The context mode. Dictates the behavior offind,fill, andcategorywithin a “with as” block when called withcontext=True.The options are as follows:
Matplotlib’s
rc_matplotlibsettings and ProPlotsrc_proplotsettings are all returned, whether or notcontexthas changed them.Unchanged
rc_matplotlibsettings returnNonebutrc_proplotsettings are returned whether or notcontexthas changed them. This is used in the__init__call toformat. When a lookup returnsNone,formatdoes not apply it.All unchanged settings return
None. This is used during user calls toformat.
Note
This is used by ProPlot internally but may also be useful for power users. It was invented to prevent successive calls to
formatfrom constantly looking up and re-applying unchanged settings. These gratuitous lookups increased runtime significantly, and resulted in successive calls toformatoverwriting the previous calls.Example
The below applies settings to axes in a specific figure using
context.>>> import proplot as pplt >>> with pplt.rc.context(ticklen=5, metalinewidth=2): >>> fig, ax = pplt.subplots() >>> ax.plot(data)
The below applies settings to a specific axes using
format, which usescontextinternally.>>> import proplot as pplt >>> fig, ax = pplt.subplots() >>> ax.format(ticklen=5, metalinewidth=2)
- fill(props, *, context=False)[source]¶
Return a dictionary filled with settings whose names match the string values in the input dictionary. Optionally limit the search to the context level.
- Parameters
See also
- find(key, *, context=False)[source]¶
Return a single setting. Optionally limit the search to the context level.
- Parameters
See also
- load(path)[source]¶
Load settings from the specified file.
- Parameters
path (path-like) – The file path.
See also
- load_file(*, new_obj=<function Configurator.load>, message="'load_file' was deprecated in version 0.8 and will be removed in a future release. Please use 'load' instead.", **kwargs)¶
- static local_files()[source]¶
Return locations of local proplotrc files in this directory and in parent directories.
- reset(local=True, user=True, default=True, **kwargs)[source]¶
Reset the configurator to its initial state.
- Parameters
local (
bool, optional) – Whether to load settings from thelocal_filesfile. Default isTrue.user (
bool, optional) – Whether to load settings from theuser_filefile. Default isTrue.default (
bool, optional) – Whether to reload built-in default ProPlot settings. Default isTrue.
- save(path=None, user=True, comment=None, backup=True, description=False)[source]¶
Save the current settings to a
proplotrcfile. This writes the default values commented out plus the values that differ from the defaults at the top of the file.- Parameters
path (path-like, optional) – The path. The default file name is
proplotrcand the default directory is the current directory.user (
bool, optional) – IfTrue(the default), the settings you changed since importing proplot are shown uncommented at the very top of the file.backup (
bool, optional) – If the file already exists and this is set toTrue, it is moved to a backup file with the suffix.bak.comment (
bool, optional) – Whether to comment out the default settings. Default is the value ofuser.description (
bool, optional) – Whether to include descriptions of each setting as comments. Default isFalse.
See also
- update(*args, **kwargs)[source]¶
Update several settings at once.
- Parameters
*args (
stror dict-like, optional) – A dictionary containingrckeys and values. You can also pass a “category” name as the first argument, in which case all settings are prepended with'category.'. For example,rc.update('axes', labelsize=20, titlesize=20)changes therc['axes.labelsize']andrc['axes.titlesize']settings.**kwargs, optional –
rckeys and values passed as keyword arguments. If the name has dots, simply omit them.
See also
- static user_file()[source]¶
Return location of the default proplotrc file. On Linux, this is either
$XDG_CONFIG_HOME/proplot/proplotrcor~/.config/proplot/proplotrcif the XDG directory is unset. On other operating systems, this is~/.proplot/proplotrc. The location~/.proplotrcor~/.proplot/proplotrcis always returned if the file exists, regardless of the operating system. If multiple valid locations are found, a warning is raised.
- static user_folder(subfolder=None)[source]¶
Return location of the default proplot folder. On Linux, this is either
$XDG_CONFIG_HOME/proplotor~/.config/proplotif the XDG directory is unset. On other operating systems, this is~/.proplot. The location~/.proplotis always returned if the folder exists, regardless of the operating system. If multiple valid locations are found, a warning is raised.