3D Visualization and Maps

Ipyvolume and pythreejs demos are below. These require separately installing these widgets. Ipyleaflet will be forthcoming, see #6903. We hope these APIs will be included upstream in the original widget repositories.

ipyvolume

There is an alpha Groovy API for ipyvolume. For this to work, the widget JS needs to be installed:

conda install -c conda-forge ipyvolume
In [ ]:
%classpath add mvn com.github.twosigma ipyvolume master-SNAPSHOT
In [ ]:
import ipyvolume.PyLab;

int size = 32;
int radius = 12;
float[][][] data = new float[size][size][size];
for (int x = 0; x<size; x++){
    for (int y = 0; y<size; y++){
        for (int z = 0; z<size; z++){
            if (Math.pow(x - size/2, 2) + Math.pow(y - size/2, 2) + Math.pow(z - size/2, 2) <= Math.pow(radius, 2)){
                data[x][y][z] = 1.0f;
            }
        }
    }
}

figure = PyLab.volShow(data)

pythreejs

There is an alpha Groovy API for pythreejs. For this to work, the widget JS needs to be installed:

conda install -c conda-forge pythreejs
In [ ]:
%classpath add mvn com.github.twosigma pythreejs master-SNAPSHOT
In [ ]:
import pythreejs.*

f = "function f(origu,origv) {\n" +
          "    // scale u and v to the ranges I want: [0, 2*pi]\n" +
          "    var u = 2*Math.PI*origu;\n" +
          "    var v = 2*Math.PI*origv;\n" +
          "    \n" +
          "    var x = Math.sin(u);\n" +
          "    var y = Math.cos(v);\n" +
          "    var z = Math.cos(u+v);\n" +
          "    \n" +
          "    return new THREE.Vector3(x,y,z)\n" +
          "}"
surf_g = new ParametricGeometry(func: f, slices: 16, stacks: 16);

surf = new Mesh(geometry: surf_g, material: new MeshLambertMaterial(color: 'green', side: 'FrontSide'))
surf2 = new Mesh(geometry: surf_g, material: new MeshLambertMaterial(color: 'yellow', side: 'BackSide'))
c = new PerspectiveCamera(position: [5, 5, 3], up: [0, 0, 1],
                      children: [new DirectionalLight(color: 'white',
                                                 position: [3, 5, 1],
                                                 intensity: 0.6d)])
scene = new Scene(children: [surf, surf2, c, new AmbientLight(intensity: 0.5d)])
renderer = new Renderer(camera: c, scene: scene, controls: [new OrbitControls(controlling: c)], _width: 400, _height: 400)