Integration with pythreejs

ipyvolume uses parts of pythreejs, giving a lot of flexibility to tweak the visualizations or behaviour. ## Materials The Scatter object has a material and line_material object, which both are a ShaderMaterial pythreejs object: https://pythreejs.readthedocs.io/en/stable/api/materials/ShaderMaterial_autogen.html.

[1]:
import ipywidgets as widgets
import numpy as np
import ipyvolume as ipv
[2]:
# a scatter plot
x, y, z = np.random.normal(size=(3, 100))
fig = ipv.figure()
scatter = ipv.scatter(x, y, z, marker='box')
scatter.connected = True  # draw connecting lines
ipv.show()

Using scatter.material we can tweak the material setting:

[3]:
scatter.material.visible = False

Or even connect a toggle button to a line_material property.

[4]:
toggle_lines = widgets.ToggleButton(description="Show lines")
widgets.jslink((scatter.line_material, 'visible'), (toggle_lines, 'value'))
toggle_lines

Controls

ipyvolume has builtin controls. For more flexibility, a Controls class from https://pythreejs.readthedocs.io/en/stable/api/controls/index.html can be contructed.

[5]:
import pythreejs
import ipyvolume as ipv
import numpy as np
fig = ipv.figure()
scatter = ipv.scatter(x, y, z, marker='box')
ipv.show()

control = pythreejs.OrbitControls(controlling=fig.camera)
# assigning to fig.controls will overwrite the builtin controls
fig.controls = control
control.autoRotate = True
# the controls does not update itself, but if we toggle this setting, ipyvolume will update the controls
fig.render_continuous = True


[6]:
control.autoRotate = True
toggle_rotate = widgets.ToggleButton(description="Rotate")
widgets.jslink((control, 'autoRotate'), (toggle_rotate, 'value'))
toggle_rotate

Camera

The camera property of ipyvolume is by default a PerspectiveCamera, but other cameras should also work: https://pythreejs.readthedocs.io/en/stable/api/cameras/index.html

[7]:
text = widgets.Text()
widgets.jslink((fig.camera, 'position'), (text, 'value'))
text