'How is the plotly 3D volume plot generated?

I've come across the following code in an example of the plotly 3D volume plots:

import plotly.graph_objects as go
import numpy as np


x1 = np.linspace(-4, 4, 9) 
y1 = np.linspace(-5, 5, 11) 
z1 = np.linspace(-5, 5, 11) 

X, Y, Z = np.meshgrid(x1, y1, z1)

values = (np.sin(X**2 + Y**2))/(X**2 + Y**2)

fig = go.Figure(data=go.Volume(
    x=X.flatten(),
    y=Y.flatten(),
    z=Z.flatten(),
    value=values.flatten(),
    opacity=0.1,
))

fig.show()

As I understand it, the 'x', 'y' and 'z' are what form the base 3D mesh cube grid and I presume that the 'value' forms the actual shape within the 3D mesh. The issue is I don't understand exactly how the 'value' field is being used to form the inner volume and the documentation doesn't seem to be at all helpful.

I initially believed that each row (or column) in the 3D values array represented a point within the mesh, but from experimentation that doesn't seem to be what's happening. Can someone please explain how this works?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source