Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interactive canvas within Jupyter Notebooks #364

Closed
dennissergeev opened this issue Aug 16, 2019 · 17 comments · Fixed by #983
Closed

Interactive canvas within Jupyter Notebooks #364

dennissergeev opened this issue Aug 16, 2019 · 17 comments · Fixed by #983
Labels
IPython/Jupyter IPython/Jupyter related topics web Using PyVista in a web-based framework

Comments

@dennissergeev
Copy link
Contributor

dennissergeev commented Aug 16, 2019

Pyvista output appears in Jupyter Notebooks as a static image, not as an interactive canvas.
This happens both in Jupyter Lab and Notebook. I also noticed that the same happens on pyvista's binder.

I can only get interactivity by using notebook=False in plot() method, which opens a separate window. It would be great to have it within a notebook, under the code cell. I think it worked for me until recently, but after updating my conda environment it doesn't.

I noticed there are some ongoing issues with widgets and pyvista (e.g. #332), but since widgets work fine in my case, I thought maybe there is a simple solution to my current problem.

Thanks.

Notes:

  • I am using a separate conda environment for pyvista.
  • The ipywidgets package works OK, with the widgets showing up and responding correctly.
  • I tried installing panel and pyviz_comms within the same environment, but the only thing that changed is that ipywidgets output now appears with a grey background (see screenshot below).

To Reproduce

Please include a code snippet to reproduce the bug in the block below:

# Insert code here
import pyvista as pv
sphere = pv.Sphere()

sphere.plot()

Screenshots
If applicable, add screenshots to help explain your problem.

Screenshot from 2019-08-16 16-28-56

System Information:
Please run the following code wherever you are experiencing the bug and paste the output below. This report helps us track down bugs and it is critical to addressing your bug:

# Get system info
import pyvista as pv
print(pv.Report())
# Paste system info here
--------------------------------------------------------------------------------
  Date: Fri Aug 16 16:34:13 2019 BST

             Linux : OS
                 8 : CPU(s)
            x86_64 : Machine
             64bit : Architecture
           31.3 GB : RAM
           Jupyter : Environment

  Python 3.7.3 | packaged by conda-forge | (default, Jul  1 2019, 21:52:21)
  [GCC 7.3.0]

            0.21.4 : pyvista
             8.2.0 : vtk
            1.17.0 : numpy
             2.5.0 : imageio
             1.4.3 : appdirs
             0.4.3 : scooby
             3.1.1 : matplotlib
             5.9.2 : PyQt5
             7.7.0 : IPython
             7.5.1 : ipywidgets
             0.6.2 : panel
--------------------------------------------------------------------------------
@banesullivan
Copy link
Member

banesullivan commented Aug 16, 2019

Hi @dennissergeev, thanks for providing your input! You're right that PyVista previously leveraged panel to embed an exported scene in the notebooks. Unfortunately, a few things changed with panel/PyVista and those embedded renderings were not working for many users so we turned off the use of panel by default in a recent release which is why you are now seeing static screenshots in the notebook (PyVista's previous default behavior before panel supported 3D rendering).

The in-notebook rendering with panel can be re-enabled by passing both use_panel=True and auto_close=False in the show() call of the plotter (or plot()). E.g.:

import pyvista as pv
sphere = pv.Sphere()

p = pv.Plotter()
p.add_mesh(sphere)
p.show(auto_close=False, use_panel=True)

2019-08-16 10 54 51

(When doing this, you may need to call pv.close_all() every once in a while to clean up the unclosed plotters)


I am currently trying to overhaul the notebook rendering abilities in #268, #300, and hoping to start using itkwidgets instead of panel, X3D, and K3D. Since the current notebook rendering with panel was always more of a proof-of-concept than a solution and it has been super buggy (see the todo list in #268), I decided it was best to disable it until we have a more stable solution as those issues were confusing many of our new users.

Until we switch to using itkwidgets, the notebook rendering will be hacky/buggy and I don't want to throw that at a new user by default - I'd rather users be aware that the notebook rendering is currently a prototype and many features simply don't work. This will remain the case until we have a working solution with itkwidgets; why? Because itkwidgets is definitely the best, extendable notebook rendering framework I've come across. See the following threads for insight:

Also, itkwidgets currently has full support for all PyVista mesh types:

import pyvista as pv
from pyvista import examples
from itkwidgets import view

mesh = examples.download_nefertiti()

view(geometries=mesh, geometry_colors='w')

2019-08-16 10 59 58

@banesullivan banesullivan added IPython/Jupyter IPython/Jupyter related topics web Using PyVista in a web-based framework labels Aug 16, 2019
@dennissergeev
Copy link
Contributor Author

Thanks a lot for the detailed explanation, @banesullivan.
The solution for using panel seems to work for me, as well as itkwidgets.

Looking forward to new versions of this great package!

@andrea-bistacchi
Copy link

Hello, I confirm plotting is static in Jupyter notebooks. What shall I do? I tried p.show(auto_close=False, use_panel=True) in some of the examples provided with PyVista, but without success (maybe I am missing something).
Thanks very much!

@banesullivan
Copy link
Member

@bistek, do you have panel installed?

@andrea-bistacchi
Copy link

andrea-bistacchi commented Oct 18, 2019

Hello @banesullivan, no I don't. I guess I should... I'll try.

@andrea-bistacchi
Copy link

Really cool! In the glacier and Euler method examples (links on the home page) there are already some cool map interaction tools, with zoom, pan etc. It's already here! I also really like the joint zoom in the Euler method example.

Thanks!

@banesullivan
Copy link
Member

FYI, v0.23.1 just introduced an experimental plotter class for itkwidgets: see #389

@dennissergeev
Copy link
Contributor Author

This is great, thanks @banesullivan!

Does this mean that exporting a scene to file (.vtkjs specifically) has more features now?

@banesullivan
Copy link
Member

Nope, the VTKjs export script is still the same and has limited functionality as it was there to demo that we could put scenes in a notebook. We likely will not expand that export script for a long time (I’m bit over committed to handle it) as we want to move towards full integration with a tool like itkwidgets for notebook plotting

Sent with GitHawk

@dennissergeev
Copy link
Contributor Author

That's cool. Looking forward to using it more in Jupyter!

Is it specifically VTKjs limitation? Are more features available if I export the scene to a different format?

@akaszynski
Copy link
Member

Scene export still seems somewhat limited for both itkwidgets and panel. I'd say that itkwidgets has slightly more features than panel right now, like user selectable colormaps, but panel is still great, and best of all you can save the outputs as static notebooks that can be loaded later without having to re-run the notebook.

Try out the new PlotterITK class and let me know if it's sufficient.

@dennissergeev
Copy link
Contributor Author

Thanks, @akaszynski !

Regarding PlotterITK: I must have installed something incorrectly, because when I try to use it, nothing appears except for the error message Error displaying widget: model not found.

Do you know what could be causing it?

pyvista report ``` Date: Tue Feb 04 10:40:10 2020 GMT
         Linux : OS
            36 : CPU(s)
        x86_64 : Machine
         64bit : Architecture
      188.6 GB : RAM
       Jupyter : Environment
    GPU Vendor : VMware, Inc.
  GPU Renderer : llvmpipe (LLVM 6.0, 256 bits)
   GPU Version : 3.3 (Core Profile) Mesa 17.3.9

Python 3.7.6 | packaged by conda-forge | (default, Jan 7 2020, 22:33:48)
[GCC 7.3.0]

        0.23.1 : pyvista
         8.2.0 : vtk
        1.17.5 : numpy
         2.6.1 : imageio
         1.4.3 : appdirs
         0.5.0 : scooby
         2.2.4 : matplotlib
        5.12.3 : PyQt5
        7.12.0 : IPython
         1.0.0 : colorcet
         0.8.0 : panel
</details>

@akaszynski
Copy link
Member

I had the exact same problem. I recommend updating jupyterlab, itkwidgets, and ipywidgets to the latest version. If that doesn't work, uninstall and reinstall jupyterlab and the required packages.

@goodok
Copy link

goodok commented Nov 19, 2020

The in-notebook rendering with panel can be re-enabled by passing both use_panel=True and auto_close=False in the show() call of the plotter (or plot()). E.g.:

As I understand, in new versions it does not work
pyvista : 0.27.2

import pyvista as pv
sphere = pv.Sphere()

p = pv.Plotter()
p.add_mesh(sphere)
p.show(auto_close=False, use_panel=True)

Result:

TypeError: "use_panel" is an invalid keyword argument for `show`

@banesullivan
Copy link
Member

Yep. Panel was always a half-baked, experimental feature and it was removed in favor of ipyvtk. See https://docs.pyvista.org/plotting/notebook_plotting/index.html

@playertr
Copy link

Yep. Panel was always a half-baked, experimental feature and it was removed in favor of ipyvtk. See https://docs.pyvista.org/plotting/notebook_plotting/index.html

New link: https://docs.pyvista.org/plotting/plotting.html#plotting-in-a-jupyter-notebook

@basnijholt
Copy link
Contributor

Yep. Panel was always a half-baked, experimental feature and it was removed in favor of ipyvtk. See https://docs.pyvista.org/plotting/notebook_plotting/index.html

New link: https://docs.pyvista.org/plotting/plotting.html#plotting-in-a-jupyter-notebook

New link: https://docs.pyvista.org/user-guide/jupyter/index.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
IPython/Jupyter IPython/Jupyter related topics web Using PyVista in a web-based framework
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants