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:
backend (
LiteralString|None) – The name of the backend to be passed toget_backend.pass_all_kwargs (
bool) – Whether to pass all keyword arguments toupdate_defaultsor just the backend-specific ones, i.e., the ones that are returned byprocess_kwargs.kwargs (
Any) – Keywords arguments passed toupdate_defaults.
- 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