Skip to content

Commit 3963827

Browse files
FIX: expose renderer.figure and reuse a passed-in scene [circle full]
The tutorials that build a renderer themselves reach for renderer.figure, which the pyvista backend exposes alongside scene(). Honour a fig argument too, so plot_alignment and plot_dipole_locations composite into one scene instead of opening a second one.
1 parent a5b4a3c commit 3963827

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

doc/sphinxext/jupyterlite_lite_renderer.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,15 @@ def __init__(self, *args, **kwargs):
9090
import pyvista_js as _pv
9191
self._np = _np
9292
self._pv = _pv
93+
# plot_alignment(fig=...) and plot_dipole_locations(fig=...) composite
94+
# into a scene the notebook already made, so draw into that plotter
95+
# rather than opening a second one and splitting the picture in two.
96+
# plot_alignment passes it positionally and create_3d_figure by name,
97+
# and `fig` is _PyVistaRenderer's first argument, so accept both.
98+
_fig = args[0] if args else kwargs.get("fig", None)
99+
if _fig is not None and hasattr(_fig, "add_mesh"):
100+
self.plotter = _fig
101+
return
93102
self.plotter = _pv.Plotter()
94103
import weakref as _weakref
95104
_lite_live_plotters.append(_weakref.ref(self.plotter))
@@ -468,6 +477,17 @@ def set_camera(self, azimuth=None, elevation=None, distance=None,
468477
# views and otherwise leave the default.
469478
return _lite_set_view(self.plotter, azimuth)
470479
480+
@property
481+
def figure(self):
482+
"""The scene, under the name the tutorials reach for.
483+
484+
``_PyVistaRenderer`` hands out one object as both ``.figure`` and
485+
``.scene()``; ``20_source_alignment`` builds a renderer itself with
486+
``create_3d_figure(scene=False)`` and then passes ``renderer.figure``
487+
to ``set_3d_view``, so the two have to stay the same thing here too.
488+
"""
489+
return self.plotter
490+
471491
def scene(self):
472492
return self.plotter
473493

0 commit comments

Comments
 (0)