By default ipyvolume uses a fake lighting model that works ok for depth perception. To get more realistic lighting effects ipyvolume supports a few light models from pythreejs/threejs.

import ipyvolume as ipv
import numpy as np
def scene():
    f = ipv.figure()
    ipv.xyzlim(-1, 1)
    x = np.array([0.1, 0.5], dtype=np.float32)
    s = ipv.scatter(x, x, x, marker="sphere", size=10);
    k = ipv.examples.klein_bottle(show=False)
    m = ipv.plot_plane('bottom')
    return f

Ambient light

For global illumination, which will not cast shadows

light = ipv.light_ambient(intensity=0.4);

Hemisphere light

A light source positioned directly above the scene, with color fading from the sky color to the ground color. This light cannot be used to cast shadows.


Directional light

A Directional Light source illuminates all objects equally from a given direction. This light can be used to cast shadows. The light is recommended together with hemisphere.

f = scene()
ipv.light_directional(position=[3, 10, 3]);

Spot light

A Spot Light produces a directed cone of light. The light becomes more intense closer to the spotlight source and to the center of the light cone. This light can be used to cast shadows.

l = ipv.light_spot(position=[0, 3, 2]);

Point light

A Point Light originates from a single point and spreads outward in all directions. This light can be used to cast shadows.

l = ipv.light_point(position=[0., 1.6, 1.0]);

Animation example

import ipyvolume as ipv
import ipyvolume.datasets
stream = ipyvolume.datasets.animated_stream.fetch()
print("shape of steam data", # first dimension contains x, y, z, vx, vy, vz, then time, then particle
shape of steam data (6, 200, 1250)
fig = ipv.figure()
# instead of doing[0],[1], ...[5], use *
# limit to 50 timesteps to avoid having a huge notebook
# q = ipv.quiver(*[:,0:200:10,:2000:10], color="red", size=7)
q = ipv.quiver(*, color="red", size=7)"dark") # looks better
m = ipv.plot_plane('bottom')
m = ipv.plot_plane('back')
m = ipv.plot_plane('left')
l = ipv.light_directional(position=[20, 50, 20], shadow_camera_orthographic_size=1, far=140, near=0.1);
ipv.animation_control(q, interval=200)


Volume rendering and lighting

For volumetric rendering we only support the Phong lighting model. No material needs to be set, only lights need to be setup.

Note that volumetric regions do not cast, not receive shadows.

import ipyvolume as ipv
# no material and lighting
volume = ipv.examples.example_ylm(shape=64, show=False)
s = ipv.scatter(x=32, y=32, z=50, size=30, marker='sphere', color="green"); = 0.24 = 0.1
volume.brightness = 2
import ipyvolume as ipv
f = ipv.figure(debug=True)
# we only add two lights

volume = ipv.examples.example_ylm(shape=64, show=False)
s = ipv.scatter(x=32, y=32, z=50, size=30, marker='sphere', color="green"); = 0.24 = 0.1
volume.material.specular = 'white'
volume.brightness = 2
/home/docs/checkouts/ DeprecationWarning: debug=True no longer needed


[ ]: