Interactive 3D-Plots inside Jupyter Notebooks and in simple web applications
See original GitHub issueI like to render an interactive 3D visualisation directly in a Jupyter notebook. For example with itkwidgets or even better use the vtk support in panel to bulid a web application.
Is there a way to somehow redirect the pyvista plot, for example created with .plot_nodal_solution()
, not in an external window but inside the jupyter notebook cell?
I managed to do this with the a Unstructured Grid but i cannot figure out how to do this with a complex plot with deflection or stress like this one:
Here is a panel web application with an interactive 3D plot.
and an example with itkwidgets (this works only in jupyter notebook, not in jupyter lab)
My code:
- panels example
# In[1]:
import pyansys
shaft = pyansys.read_binary('shaft_modal.rst')
# In[2]:
import panel as pn
pn.extension('vtk')
# In[3]:
import pyvista as pv
pl = pv.Plotter()
pl.add_mesh(shaft.grid)
pan = pn.panel(pl.ren_win, sizing_mode='stretch_width', orientation_widget=True)
app = pn.Row(pn.Column(pan, pan.construct_colorbars()), pn.pane.Str(type(pl.ren_win), width=500))
app
# In[4]:
pn.serve(app)
- itkwidgets example
# In[1]:
import pyansys
from itkwidgets import view
# In[2]:
shaft = pyansys.read_binary('shaft_modal.rst')
view(geometries=shaft.grid)
It would be great if one could simply “redirect” the plot and use compatible visualisation libraries.
By the way, thank you very much for the great work you have done with Pyansys!
Issue Analytics
- State:
- Created 3 years ago
- Comments:11 (10 by maintainers)
This works as-is as of the last two pyvista releases.
We’ve finally been able to add this as a feature in the upstream dependency
pyvista
. To enable in-notebook plotting, please install the latestpyvista
and the latestipyvtk-simple
and then set the default notebook plottter toipyvtk-simple
with:The cool part is it runs with all the current examples and doesn’t involve changing any of the plotting backend. Here’s a video of it working on the shaft example.
Just some background: Turns out that it’s far easier to implement server-side plotting rather than client side plotting, especially since
itkwidgets
doesn’t have the same feature set as the full VTK library. Please see the additional documentation about this at [ipyvtk-simple Plotting].(https://docs.pyvista.org/plotting/notebook_plotting/ipyvtk_plotting.html#installation)