CoCalc Public Filesipyvolume-demo.htmlOpen with one click!
Authors: Harald Schilly, Harald Schilly, ℏal Snyder
Views : 125
Description: ipyvolume demo
Compute Environment: Ubuntu 18.04 (Deprecated)
ipyvolume-demo

IpyVolume on CoCalc

https://ipyvolume.readthedocs.io/en/latest/index.html

  • Python 3 (Ubuntu Linux)
  • Plain Jupyter Notebook Server
  • Internet access necessary (hdz2000, ... datasets)
In [1]:
import ipyvolume
In [2]:
ipyvolume.__version__
Out[2]:
'0.5.1'
In [3]:
import ipyvolume as ipv
import numpy as np
In [4]:
hdz = ipv.datasets.hdz2000.fetch()
In [5]:
ipv.pylab.volshow(hdz.data)
/usr/local/lib/python3.6/dist-packages/ipyvolume/serialize.py:81: RuntimeWarning: invalid value encountered in true_divide
  gradient = gradient / np.sqrt(gradient[0]**2 + gradient[1]**2 + gradient[2]**2)
In [6]:
# only x is a sequence of arrays
x = np.array([[-1, -0.8], [1, -0.1], [0., 0.5]])
y = np.array([0.0, 0.0])
z = np.array([0.0, 0.0])
ipv.figure()
s = ipv.scatter(x, y, z, marker='sphere', size=10)
ipv.xyzlim(-1, 1)
ipv.animation_control(s) # shows controls for animation controls
ipv.show()
In [7]:
# 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)

# 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)

# draw the scatter plot, and add controls with animate_glyphs
ipv.figure()
s = ipv.scatter(x, z, y, marker="sphere")
ipv.animation_control(s, interval=200)
ipv.ylim(-3,3)
ipv.show()
x,y and z are of shape (25, 25)
and flattened of shape (625,)
z is of shape (15, 625)
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [8]:
X = np.arange(-5, 5, 0.25*1)
Y = np.arange(-5, 5, 0.25*1)
X, Y = np.meshgrid(X, Y)
R = np.sqrt(X**2 + Y**2)
Z = np.sin(R)
In [9]:
from matplotlib import cm
colormap = cm.coolwarm
znorm = Z - Z.min()
znorm /= znorm.ptp()
znorm.min(), znorm.max()
color = colormap(znorm)
In [10]:
ipv.figure()
mesh = ipv.plot_surface(X, Z, Y, color=color[...,:3])
ipv.show()
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]: