ipyvolume uses parts of pythreejs, giving a lot of flexibility to tweak the visualizations or behaviour.
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.
In [ ]:
import ipywidgets as widgets
import numpy as np
import ipyvolume as ipv
In [ ]:
# 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:
In [ ]:
scatter.material.visible = False
Or even connect a toggle button to a line_material property.
In [ ]:
toggle_lines = widgets.ToggleButton(description="Show lines")
widgets.jslink((scatter.line_material, 'visible'), (toggle_lines, 'value'))
toggle_lines
ipyvolume has builtin controls. For more flexibility, a Controls class from https://pythreejs.readthedocs.io/en/stable/api/controls/index.html can be contructed.
In [ ]:
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
In [ ]:
control.autoRotate = True
toggle_rotate = widgets.ToggleButton(description="Rotate")
widgets.jslink((control, 'autoRotate'), (toggle_rotate, 'value'))
toggle_rotate
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
In [ ]:
text = widgets.Text()
widgets.jslink((fig.camera, 'position'), (text, 'value'))
text