differt.plotting.reuse

Contents

differt.plotting.reuse#

reuse(backend=None, pass_all_kwargs=False, **kwargs)[source]#

Create a context manager that will automatically reuse the current canvas / figure.

Parameters:
Yields:

The canvas or figure that is reused for this context.

Return type:

Iterator[SceneCanvas | Figure | Figure]

Examples

The following example show how the same figure is reused for multiple plots.

>>> from differt.plotting import draw_image, reuse
>>>
>>> x = np.linspace(-1.0, +1.0, 100)
>>> y = np.linspace(-4.0, +4.0, 200)
>>> X, Y = np.meshgrid(x, y)
>>>
>>> with reuse(backend="plotly") as fig:
...     for z0, w in enumerate(jnp.linspace(0, 10 * jnp.pi, 5)):
...         Z = np.cos(w * X) * np.sin(w * Y)
...         draw_image(Z, x=x, y=y, z0=z0)  # TODO: fix colorbar
>>> fig