Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
b9667cf
Initial commit
lukelbd Dec 19, 2019
83ef32c
Merge branch 'master' into rc-cleanup-fixes
lukelbd Jan 6, 2020
e464a99
Move default props from .proplotrc --> rctools.py
lukelbd Jan 6, 2020
e760807
Improve rc_configurator getitem/setitem, add helper func
lukelbd Jan 6, 2020
d6b6020
Update get(), fill(), category(); add dict() and iterator methods
lukelbd Jan 6, 2020
a82dd68
Fix rc_configurator.context() bug
lukelbd Jan 6, 2020
dea6d94
Improve iter, contains, and string repr methods
lukelbd Jan 6, 2020
44a4bc9
Improve _loc_translate + _get_title_props, related cleanup
lukelbd Jan 7, 2020
424bc67
Remove Axes.context, update rc lookups, related cleanup
lukelbd Jan 7, 2020
8e7655e
Add x/ylinewidth, x/ygridcolor XYAxes.format kwargs
lukelbd Jan 7, 2020
25f7bd8
Fix rc lookups in other files
lukelbd Jan 7, 2020
77e406a
Remove Axes.context, add documented Axes.number prop
lukelbd Jan 7, 2020
61a45d4
Update changelog and index
lukelbd Jan 7, 2020
93c8aa5
Cleaner install instructions
lukelbd Jan 7, 2020
da123eb
Remove rc._init reference
lukelbd Jan 7, 2020
5b45522
Fix bug/conflict between ipython_* funcs and rc.__init__
lukelbd Jan 7, 2020
1bf78ce
Remove _getitem_mode assignment
lukelbd Jan 7, 2020
3c44865
Add _get_space function, simplify _panel_kwargs function
lukelbd Jan 7, 2020
3fb9a52
Rename _panel_kwargs --> _get_panelargs
lukelbd Jan 7, 2020
dba9f70
Use _get_space; remove refs to subplots.ylabspace, etc.
lukelbd Jan 7, 2020
fdfe042
Update default font sizes
lukelbd Jan 7, 2020
3218c2a
Change refs from panelspace --> panelpad
lukelbd Jan 7, 2020
1ab92ca
Remove subplots.ylabspace, etc. from configuration docs
lukelbd Jan 7, 2020
16ae44f
Fix _loc_translate bug
lukelbd Jan 7, 2020
6629efb
Remove panel_kw from colorbar/legend_wrapper
lukelbd Jan 7, 2020
ef33694
Update changelog
lukelbd Jan 7, 2020
20b9f5b
No longer change figure.dpi
lukelbd Jan 7, 2020
db78bc0
Fix rc.category bug, minor subplots bugs
lukelbd Jan 7, 2020
c57c7b0
Prefer closing brackets on new lines
lukelbd Jan 7, 2020
578aa8b
Better install instructions
lukelbd Jan 7, 2020
7acffb6
Update changelog
lukelbd Jan 7, 2020
8da19f5
Remove outdated cache=False ref, remove debug statement
lukelbd Jan 7, 2020
3ca9a02
Minor BasemapAxes bugfix
lukelbd Jan 7, 2020
22af8f9
Notebook examples formatting improvements
lukelbd Jan 7, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix rc_configurator.context() bug
  • Loading branch information
lukelbd committed Jan 6, 2020
commit a82dd689bbd4ba5a533e8477a7b4315f0a70b4b4
65 changes: 38 additions & 27 deletions proplot/rctools.py
Original file line number Diff line number Diff line change
Expand Up @@ -866,32 +866,33 @@ def category(self, cat, *, context=False):

def context(self, *args, mode=0, **kwargs):
"""
Temporarily modifies settings in a ``with...as`` block,
used by ProPlot internally but may also be useful for power users.
Temporarily modify the rc settings in a "with as" block.

This function was invented to prevent successive calls to
This is used by ProPlot internally but may also be useful for power
users. It was invented to prevent successive calls to
`~proplot.axes.Axes.format` from constantly looking up and
re-applying unchanged settings. Testing showed that these gratuitous
`rcParams <https://matplotlib.org/users/customizing.html>`__
lookups and artist updates increased runtime by seconds, even for
relatively simple plots.
relatively simple plots. It also resulted in overwriting previous
rc changes with the default values upon subsequent calls to
`~proplot.axes.Axes.format`.

Parameters
----------
*args
Dictionaries of setting names and values.
Dictionaries of `rc` names and values.
**kwargs
Setting names and values passed as keyword arguments.
`rc` names and values passed as keyword arguments. If the
name has dots, simply omit them.

Other parameters
----------------
mode : {0,1,2}, optional
The `~rc_configurator.__getitem__` mode.
Dictates the behavior of the `rc` object within a ``with...as``
block when settings are requested with e.g. :rcraw:`setting`. If
you are using `~rc_configurator.context` manually, the `mode` is
automatically set to ``0`` -- other input is ignored. Internally,
ProPlot uses all of the three available modes.
The context mode. Dictates the behavior of `~rc_configurator.get`,
`~rc_configurator.fill`, and `~rc_configurator.category` within a
"with as" block when called with ``context=True``. The options are
as follows.

0. All settings (`rcParams \
<https://matplotlib.org/users/customizing.html>`__,
Expand All @@ -901,29 +902,37 @@ def context(self, *args, mode=0, **kwargs):
<https://matplotlib.org/users/customizing.html>`__
return ``None``. :ref:`rcParamsLong` and :ref:`rcParamsShort`
are returned whether or not `~rc_configurator.context` has
changed them. This is used in the ``__init__`` call to
`~proplot.axes.Axes.format`. When a setting lookup returns
changed them. This is used in the `~proplot.axes.Axes.__init__`
call to `~proplot.axes.Axes.format`. When a lookup returns
``None``, `~proplot.axes.Axes.format` does not apply it.
2. All unchanged settings return ``None``. This is used during user
calls to `~proplot.axes.Axes.format`.

Example
-------
The below applies settings to axes in a specific figure using
`~rc_configurator.context`.

>>> import proplot as plot
>>> with plot.rc.context(linewidth=2, ticklen=5):
... f, ax = plot.subplots()
... ax.plot(data)

By contrast, the below applies settings to a specific axes using
`~proplot.axes.Axes.format`.

>>> import proplot as plot
>>> f, ax = plot.subplots()
>>> ax.format(linewidth=2, ticklen=5)

"""
if mode not in range(3):
raise ValueError(f'Invalid _getitem_mode {mode}.')
raise ValueError(f'Invalid mode {mode!r}.')
for arg in args:
if not isinstance(arg, dict):
raise ValueError('Non-dictionary argument.')
raise ValueError('Non-dictionary argument {arg!r}.')
kwargs.update(arg)
self._context = kwargs # could be empty
self._getitem_mode = mode
self._context.append((mode, kwargs, {}, {}))
return self

def dict(self):
Expand Down Expand Up @@ -993,20 +1002,22 @@ def keys(self):

def update(self, *args, **kwargs):
"""
Bulk updates settings, usage is similar to python `dict` objects.
Update multiple settings at once.

Parameters
----------
*args : str, dict, or (str, dict)
Positional arguments can be a dictionary of `rc` settings and/or
a "category" string name. If a category name is passed, all
settings in the dictionary (if it was passed) and all keyword arg
names (if they were passed) are prepended with the string
``cat + '.'``. For example,
``rc.update('axes', labelsize=20, titlesize=20)``
changes the ``axes.labelsize`` and ``axes.titlesize`` properties.
The first argument can optionally be a "category" string name,
in which case all other setting names passed to this function are
prepended with the string ``cat + '.'``. For example,
``rc.update('axes', labelsize=20, titlesize=20)`` changes the
:rcraw:`axes.labelsize` and :rcraw:`axes.titlesize` properties.

The first or second argument can also be a dictionary of `rc`
names and values.
**kwargs
`rc` settings passed as keyword args.
`rc` names and values passed as keyword arguments. If the
name has dots, simply omit them.
"""
# Parse args
kw = {}
Expand Down