ipyvolume https://github.com/maartenbreddels/ipyvolume

3d plotting for Python in the Jupyter notebook

IPyvolume is a Python library to visualize 3d volumes and glyphs (e.g. 3d scatter plots), in the Jupyter notebook, with minimal configuration and effort. It is currently pre-1.0, so use at own risk. IPyvolume’s volshow is to 3d arrays what matplotlib’s imshow is to 2d arrays.

  • MIT Licensed

By Maarten Breddels

Installation:

conda install -c conda-forge ipyvolume

3-D Scatter Plots


In [1]:
import ipyvolume
import numpy as np
x, y, z = np.random.random((3, 10000))
ipyvolume.quickscatter(x, y, z, size=1, marker="sphere")



In [2]:
import ipyvolume.pylab as p3
import numpy as np
x, y, z, u, v, w = np.random.random((6, 1000))*2-1
selected = np.random.randint(0, 1000, 100)
p3.figure()
quiver = p3.quiver(x, y, z, u, v, w, size=5, size_selected=8, selected=selected)

from ipywidgets import FloatSlider, ColorPicker, VBox, jslink
size = FloatSlider(min=0, max=30, step=0.1)
size_selected = FloatSlider(min=0, max=30, step=0.1)
color = ColorPicker()
color_selected = ColorPicker()
jslink((quiver, 'size'), (size, 'value'))
jslink((quiver, 'size_selected'), (size_selected, 'value'))
jslink((quiver, 'color'), (color, 'value'))
jslink((quiver, 'color_selected'), (color_selected, 'value'))
VBox([p3.gcc(), size, size_selected, color, color_selected])


Animations


In [3]:
import ipyvolume.pylab as p3
import numpy as np

In [4]:
# create 2d grids: x, y, and r
u = np.linspace(-10, 10, 25)
x, y = np.meshgrid(u, u)
r = np.sqrt(x**2+y**2)
print("x,y and z are of shape", x.shape)
# and turn them into 1d
x = x.flatten()
y = y.flatten()
r = r.flatten()
print("and flattened of shape", x.shape)


x,y and z are of shape (25, 25)
and flattened of shape (625,)

In [5]:
# create a sequence of 15 time elements
time = np.linspace(0, np.pi*2, 15)
z = np.array([(np.cos(r + t) * np.exp(-r/5)) for t in time])
print("z is of shape", z.shape)


z is of shape (15, 625)

In [6]:
# draw the scatter plot, and add controls with animate_glyphs
p3.figure()
s = p3.scatter(x, z, y, marker="sphere")
p3.animate_glyphs(s, interval=200)
p3.ylim(-3,3)
p3.show()


/Users/scorlay/miniconda3/lib/python3.6/site-packages/ipykernel_launcher.py:4: DeprecationWarning: Please use animation_control(...)
  after removing the cwd from sys.path.