Skip to content

iPython Inline Viewer

from vape4d import viewer
from vape4d.utils import diverging_alpha
import numpy as np
from matplotlib import pyplot as plt
def volume(t):
    x = np.linspace(-1,1,8)
    y = np.linspace(-1,1,8)
    z = np.linspace(-1,1,8)
    X,Y,Z = np.meshgrid(x,y,z)
    return np.sin(t*2*np.pi*(X+Y+Z))

# the diverging_alpha function creates a colormap that is transparent at the ends
cmap = diverging_alpha(plt.get_cmap("magma"))

volum4d = np.stack([volume(t) for t in np.linspace(0,1,32)])[:,None]

viewer(
    volum4d,
    cmap,
    duration=10.,
    distance_scale=2.
)

Standalone Viewerยค

We can also save the volume as a NPZ/NPY file and open it in the standalone viewer.

np.save("my_first_volume.npy",volum4d)

Go to https://keksboter.github.io/vape4d/ and open the my_first_volume.npz file.