Configurator¶
- class Configurator(local=True, user=True, default=True, **kwargs)[source]¶
Bases:
collections.abc.MutableMapping
,dict
A dictionary-like class for managing matplotlib settings stored in
rc_matplotlib
and ProPlot settings stored inrc_proplot
. This class is instantiated as therc
object on import. See the user guide for details.- Parameters
local (
bool
, optional) – Whether to load settings from thelocal_files
file. Default isTrue
.user (
bool
, optional) – Whether to load settings from theuser_file
file. 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
proplotrc
file.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
, andcategory
within a “with as” block when called withcontext=True
.The options are as follows:
Matplotlib’s
rc_matplotlib
settings and ProPlotsrc_proplot
settings are all returned, whether or notcontext
has changed them.Unchanged
rc_matplotlib
settings returnNone
butrc_proplot
settings are returned whether or notcontext
has changed them. This is used in the__init__
call toformat
. When a lookup returnsNone
,format
does 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
format
from constantly looking up and re-applying unchanged settings. These gratuitous lookups increased runtime significantly, and resulted in successive calls toformat
overwriting 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 usescontext
internally.>>> 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_files
file. Default isTrue
.user (
bool
, optional) – Whether to load settings from theuser_file
file. 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
proplotrc
file. 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
proplotrc
and 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 (
str
or dict-like, optional) – A dictionary containingrc
keys 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 –
rc
keys 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/proplotrc
or~/.config/proplot/proplotrc
if the XDG directory is unset. On other operating systems, this is~/.proplot/proplotrc
. The location~/.proplotrc
or~/.proplot/proplotrc
is 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/proplot
or~/.config/proplot
if the XDG directory is unset. On other operating systems, this is~/.proplot
. The location~/.proplot
is always returned if the folder exists, regardless of the operating system. If multiple valid locations are found, a warning is raised.