Configurator.context

Configurator.context(*args, mode=0, file=None, **kwargs)[source]

Temporarily modify the rc settings in a “with as” block.

Parameters
  • *args – Dictionaries of rc keys and values.

  • file (path-like, optional) – Filename from which settings should be loaded.

  • **kwargsrc names and values passed as keyword arguments. If the name has dots, simply omit them.

Other Parameters

mode ({0, 1, 2}, optional) – The context mode. Dictates the behavior of find, fill, and category within a “with as” block when called with context=True.

The options are as follows:

  1. Matplotlib’s rc_matplotlib settings and proplots rc_proplot settings are all returned, whether or not context has changed them.

  2. Unchanged rc_matplotlib settings return None but rc_proplot settings are returned whether or not context has changed them. This is used in the __init__ call to format. When a lookup returns None, format does not apply it.

  3. All unchanged settings return None. This is used during user calls to format.

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 to format 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 uses context internally.

>>> import proplot as pplt
>>> fig, ax = pplt.subplots()
>>> ax.format(ticklen=5, metalinewidth=2)