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

RGBA color support inside a Jupyter Notebook #15

Closed
GuillaumeFavelier opened this issue Jun 17, 2019 · 5 comments
Closed

RGBA color support inside a Jupyter Notebook #15

GuillaumeFavelier opened this issue Jun 17, 2019 · 5 comments
Assignees
Labels
IPython/Jupyter Questions around using PyVista in IPython/Jupyter plotting General plotting/rendering topics

Comments

@GuillaumeFavelier
Copy link

When I use RGBA colors inside a Jupyter Notebook, I obtain an unexpected result:

import pyvista as pv
import numpy as np

sphere = pv.Sphere()
scalars = np.ones((sphere.GetNumberOfPoints(), 4)) * 255.0
scalars = scalars.astype('ubyte')

p = pv.Plotter()
p.add_mesh(sphere, rgba=True, scalars=scalars)
p.show()

image

When I run this script natively, I get the right result of course:

image

@GuillaumeFavelier GuillaumeFavelier added the IPython/Jupyter Questions around using PyVista in IPython/Jupyter label Jun 17, 2019
@GuillaumeFavelier
Copy link
Author

GuillaumeFavelier commented Jun 17, 2019

Now that I think about it, maybe this could be fixed by #258 ? Well, it's also possible that my code snippet isn't correct.

@banesullivan
Copy link
Member

banesullivan commented Jun 17, 2019

It's not your code, it's panel's converter to VTKjs (see holoviz/panel#408).

At the moment, we are using panel's export script rather than ours to convert the scene to VTKjs when making the embeddable rendering scenes; there are a number of bugs (and most of those bugs exist in our script too). We need to move forward with bug fixing the export script in PyVista to work with panel to avoid this issue.

Perhaps pyvista/pyvista#258 would be a better approach and more worth our time. K3D seems far more robust than VTKjs so maybe we should focus on creating a way to display PyVista scenes with K3D rather than fixing the VTKjs script.

@banesullivan banesullivan added the plotting General plotting/rendering topics label Jun 17, 2019
@banesullivan
Copy link
Member

banesullivan commented Jun 17, 2019

Also, I've found a hack of a fix. If you only have a single array present in the dataset you'd like to send to VTKjs, it'll work:

import pyvista as pv
import numpy as np

sphere = pv.Sphere()
scalars = np.ones((sphere.GetNumberOfPoints(), 4)) * 255.0
scalars = scalars.astype('ubyte')

# ONLY have one array present for VTKjs
# del sphere.point_arrays['Normals']
sphere.clear_arrays()

p = pv.Plotter()
p.add_mesh(sphere, rgba=True, scalars=scalars)
p.show()

Screen Shot 2019-06-17 at 8 30 12 AM

@GuillaumeFavelier
Copy link
Author

This hack is already amazing as a short-term solution, thank you so much! I will try it. So out of curiosity, is it the array of Normals which is displayed by default then?

And the choice between K3D and VTKjs looks like a dilemma. Even if I looked their showcase gallery, I still need to try K3D myself to have a better understanding of its capabilities.

@banesullivan
Copy link
Member

So out of curiosity, is it the array of Normals which is displayed by default then?

The VTKjs export script has trouble choosing the active array. It always grabs the array at the 0th index so if you remove all other arrays other than what you want to plot it should work fine.

I still need to try K3D myself to have a better understanding of its capabilities.

I definitely need to look into it more as well

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
IPython/Jupyter Questions around using PyVista in IPython/Jupyter plotting General plotting/rendering topics
Projects
None yet
Development

No branches or pull requests

2 participants