pyvista-support icon indicating copy to clipboard operation
pyvista-support copied to clipboard

PlotterITK Ignores colors in Jupyter Notebook

Open TroyWilliams3687 opened this issue 4 years ago • 4 comments

When I am trying to use PlotterITK in Jupyter notebooks, the color parameter is ignored. I am experimenting with a 3D visualizer that can complement matplotlib and am looking at pyvista. So far, it was pretty easy to get started and I was able to plot some of the 3D work from matplotlib in it almost trivially.

I am running it on Ubuntu 20.04 and for the most part it seems to operate fine except the PlotterITK ignores color. I am pretty sure I have all of the dependencies installed, here is the pv.report output:

print(pv.Report())

--------------------------------------------------------------------------------
  Date: Sat Oct 31 08:45:49 2020 EDT

                OS : Linux
            CPU(s) : 5
           Machine : x86_64
      Architecture : 64bit
       Environment : Jupyter
        GPU Vendor : NVIDIA Corporation
      GPU Renderer : GeForce GT 610/PCIe/SSE2
       GPU Version : 4.5.0 NVIDIA 390.138

  Python 3.8.3 (default, Jul 11 2020, 14:14:20)  [GCC 9.3.0]

           pyvista : 0.26.1
               vtk : 9.0.1
             numpy : 1.19.3
           imageio : 2.9.0
           appdirs : 1.4.4
            scooby : 0.5.6
            meshio : 4.3.2
        matplotlib : 3.3.2
           IPython : 7.19.0
          colorcet : 1.0.0
             scipy : 1.5.3
        itkwidgets : 0.32.0
--------------------------------------------------------------------------------

I am also running Jupyter notebook server v6.1.4-bdf3987 with IPython v7.19.0 of the kernel.

If I run this code:

import pyvista as pv

pv.set_plot_theme('document')

mesh = pv.Sphere()
pl = pv.Plotter(notebook=True)
pl.add_mesh(mesh, color='blue')
pl.show()

I get this: image

It followed the color='blue'.

If I run this code:

mesh = pv.Sphere()
pl = pv.PlotterITK()
pl.add_mesh(mesh, color='blue')
pl.show()

It ignores the color option: image

It is not a huge deal, because I can use the ITK menu to change the colors and styles. But it is annoying to have to do it every time particularly when I have dozens of meshes and other structures that should have their own colors.

I have also found if I set notebook=False:

pl = pv.Plotter(notebook=False)

It pops up a window - I do like this very much and found that I can control a lot of defaults, the colors work, etc. This would work for me and would be a great option in a lot of cases once I am done prototyping. However, when I am done with the external window it hangs around and doesn't close until I stop jupyter. The output windows freeze up and I cannot control close it or move it. When I run the code again, another separate window pops up. Any thoughts on this?

TroyWilliams3687 avatar Oct 31 '20 13:10 TroyWilliams3687

I found out about the background plotting (https://docs.pyvista.org/plotting/plotting.html). I tried that

import pyvista as pv
import pyvistaqt as pvqt
from pyvista import examples

dataset = examples.load_uniform()

plotter = pvqt.BackgroundPlotter()
plotter.add_mesh(dataset)

# Then in another cell, you can add more to the plotter
plotter.show_bounds()

I tried that and that works quite nicely. The window closes when I don't need it and it is much easier to interact with than in the jupyter cell. Would still be nice to understand if it is possible to have an embedded interactive widget that takes the color. That way I can provide a choice of how to view the plots :)

TroyWilliams3687 avatar Oct 31 '20 14:10 TroyWilliams3687

Confirmed: I also have the same color issue on Mac OS X:

$ print(pv.Report())
--------------------------------------------------------------------------------
  Date: Thu Jan 07 01:31:14 2021 PST

                OS : Darwin
            CPU(s) : 8
           Machine : x86_64
      Architecture : 64bit
               RAM : 16.0 GB
       Environment : Jupyter
        GPU Vendor : Intel Inc.
      GPU Renderer : Intel Iris Pro OpenGL Engine
       GPU Version : 4.1 INTEL-12.10.25

  Python 3.8.6 | packaged by conda-forge | (default, Dec 26 2020, 04:50:20)
  [Clang 11.0.0 ]

           pyvista : 0.27.4
               vtk : 9.0.1
             numpy : 1.19.2
           imageio : 2.9.0
           appdirs : 1.4.4
            scooby : 0.5.6
            meshio : 4.3.8
        matplotlib : 3.3.3
             PyQt5 : 5.12.3
           IPython : 7.19.0
          colorcet : 1.0.0
             scipy : 1.5.3
        itkwidgets : 0.32.0
              tqdm : 4.55.1

  Intel(R) Math Kernel Library Version 2020.0.4 Product Build 20200917 for
  Intel(R) 64 architecture applications
--------------------------------------------------------------------------------

mforbes avatar Jan 07 '21 09:01 mforbes

This issue has been bugging me as well. When I want to add a few things to a plot I find myself having to create scalars (for example: 0, 0.5, and 1 for 3 different objects) and use a color map just so that I can distinguish between 3 different meshes.

Example with color not working:

image

Example with contrived scalars to get color:

image

You could actually get any desired color you want if you could change the colormap to something like Spectal or jet and select an appropriate scalar, but the cmap argument doesn't appear to work for PlotterITK either.

flutefreak7 avatar Mar 16 '21 21:03 flutefreak7

itkwidgets doesn't support jupyterlab 3 either, so I hope it gets some attention soon. I'm going to be proposing a PR with additional jupyterlab support soon, so please be on the watch for it (supporting panel and ipygany).

akaszynski avatar Mar 17 '21 03:03 akaszynski