3D Volume Plots in Julia

How to make 3D Volume Plots in Julia with Plotly.


A volume plot with volume shows several partially transparent isosurfaces for volume rendering. The API of volume is close to the one of isosurface. However, whereas isosurface plots show all surfaces with the same opacity, tweaking the opacityscale parameter of volume results in a depth effect and better volume rendering.

Basic volume plot

In the three examples below, note that the default colormap is different whether isomin and isomax have the same sign or not.

using PlotlyJS

data = range(-8, stop=8, length=40)
X, Y, Z = mgrid(data, data, data)

values = sin.(X .* Y .* Z) ./ (X .* Y .* Z)

plot(volume(
    x=X[:],
    y=Y[:],
    z=Z[:],
    value=values[:],
    isomin=0.1,
    isomax=0.8,
    opacity=0.1, # needs to be small to see through all surfaces
    surface_count=17, # needs to be a large number for good volume rendering
))