question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Interactive 3D-Plots inside Jupyter Notebooks and in simple web applications

See original GitHub issue

I 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: Screenshot 2020-05-10 at 12 53 12

Here is a panel web application with an interactive 3D plot. panel

and an example with itkwidgets (this works only in jupyter notebook, not in jupyter lab) Screenshot 2020-05-10 at 12 38 59

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:closed
  • Created 3 years ago
  • Comments:11 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
akaszynskicommented, Jul 7, 2022

This works as-is as of the last two pyvista releases.

1reaction
akaszynskicommented, Nov 19, 2020

We’ve finally been able to add this as a feature in the upstream dependency pyvista. To enable in-notebook plotting, please install the latest pyvista and the latest ipyvtk-simple and then set the default notebook plottter to ipyvtk-simple with:

import pyvista
pyvista.rcParams['use_ipyvtk'] = True

#  pyansys code follows

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.

Untitled_ Nov 19, 2020 2_34 PM


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)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Make 3D interactive Matplotlib plot in Jupyter Notebook
To generate an interactive 3D plot first import the necessary packages and create a random dataset. Now using Axes3D(figure) function from the ...
Read more >
Python & Matplotlib: Make 3D plot interactive in Jupyter ...
This shows an interactive 3D plot inside a notebook, which still works in nbviewer. The visjs code is borrowed from the example code...
Read more >
Interactive 3D-Plots inside Jupyter Notebooks and in ... - GitHub
I like to render an interactive 3D visualisation directly in a Jupyter notebook. For example with itkwidgets or even better use the vtk ......
Read more >
Interactive 3D Visualization in Jupyter | SciPy 2018 - YouTube
I will present ipyvolume, which is a 3d plotting library for the Jupyter notebook. Being an Jupyter widget, it plays well together with ......
Read more >
Jupyter notebook tutorial in Python - Plotly
Plotly: a graphing library for making interactive, publication-quality graphs. See examples of statistic, scientific, 3D charts, and more here: https://plotly.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found