In [30]:
import ipyvolume as ipv
import numpy as np


n_radii = 8
n_angles = 36

# Make radii and angles spaces (radius r=0 omitted to eliminate duplication).
radii = np.linspace(0.125, 1.0, n_radii)
angles = np.linspace(0, 2*np.pi, n_angles, endpoint=False)

# Repeat all angles for each radius.
angles = np.repeat(angles[..., np.newaxis], n_radii, axis=1)

# Convert polar (radii, angles) coords to cartesian (x, y) coords.
# (0, 0) is manually added at this stage,  so there will be no duplicate
# points in the (x, y) plane.
x = np.append(0, (radii*np.cos(angles)).flatten())
y = np.append(0, (radii*np.sin(angles)).flatten())

# Compute z to make the pringle surface.
z = np.sin(-x*y)

In [32]:
ipv.figure()
ipv.plot_mesh(x, y, z)
ipv.show()


---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-32-bcecc14a406f> in <module>()
      1 ipv.figure()
----> 2 ipv.plot_mesh(x, y, z)
      3 ipv.show()

/usr/local/lib/python3.7/site-packages/ipyvolume/pylab.py in plot_mesh(x, y, z, color, wireframe, surface, wrapx, wrapy, u, v, texture)
    294         nx, ny = shape = x.shape
    295     else:
--> 296         nx, ny = shape = x[0].shape
    297 
    298     def reshape(ar):

ValueError: not enough values to unpack (expected 2, got 0)

In [37]:
from mpl_toolkits.mplot3d import axes3d

# Grab some test data.
X, Y, Z = axes3d.get_test_data(0.05)
ipv.figure()
ipv.plot_mesh(X, Y, Z, color=)
ipv.show()


---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-37-f0d86f4461ce> in <module>()
      4 X, Y, Z = axes3d.get_test_data(0.05)
      5 ipv.figure()
----> 6 ipv.plot_mesh(X, Y, Z, color=x*5)
      7 ipv.show()

/usr/local/lib/python3.7/site-packages/ipyvolume/pylab.py in plot_mesh(x, y, z, color, wireframe, surface, wrapx, wrapy, u, v, texture)
    311         # if dim(color) == 4:
    312         #       color = color.reshape((color.shape[0], -1, color.shape[-1]))
--> 313         color = reshape_color(color)
    314         # print(color.shape)
    315 

/usr/local/lib/python3.7/site-packages/ipyvolume/pylab.py in reshape_color(ar)
    306             return [k.reshape(-1, 3) for k in ar]
    307         else:
--> 308             return ar.reshape(-1, 3)
    309 
    310     if isinstance(color, np.ndarray):

ValueError: cannot reshape array of size 289 into shape (3)

In [34]:
ipv.plot_mesh?


Signature: ipv.plot_mesh(x, y, z, color='red', wireframe=True, surface=True, wrapx=False, wrapy=False, u=None, v=None, texture=None)
Docstring:
Draws a 2d wireframe+surface in 3d: generalization of :any:`plot_wireframe` and :any:`plot_surface`

:param x: {x2d}
:param y: {y2d}
:param z: {z2d}
:param color: {color2d}
:param bool wireframe: draw lines between the vertices
:param bool surface: draw faces/triangles between the vertices
:param bool wrapx: when True, the x direction is assumed to wrap, and polygons are drawn between the begin and end points
:param boool wrapy: idem for y
:param u: {u}
:param v: {v}
:param texture: {texture}
:return: :any:`Mesh`
File:      /usr/local/lib/python3.7/site-packages/ipyvolume/pylab.py
Type:      function

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

s = 1/2**0.5
# 4 vertices for the tetrahedron
x = np.array([1.,  -1, 0,  0])
y = np.array([0,   0, 1., -1])
z = np.array([-s, -s, s,  s])
# and 4 surfaces (triangles), where the number refer to the vertex index
triangles = [(0, 1, 2), (0, 1, 3), (0, 2, 3), (1,3,2)]

p3.figure()
# we draw the tetrahedron
p3.plot_trisurf(x, y, z, triangles=triangles, color='orange')
# and also mark the vertices
p3.scatter(x, y, z, marker='sphere', color='blue')
p3.xyzlim(-2, 2)
p3.show()



In [39]:
# f(u, v) -> (u, v, u*v**2)
a = np.arange(-5, 5)
U, V = np.meshgrid(a, a)
X = U
Y = V
Z = X*Y**2
p3.figure()
p3.plot_surface(X, Z, Y, color="orange")
p3.plot_wireframe(X, Z, Y, color="black")
p3.show()



In [40]:
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)

from matplotlib import cm
colormap = cm.coolwarm
znorm = Z - Z.min()
znorm /= znorm.ptp()
znorm.min(), znorm.max()
color = colormap(znorm)

p3.figure()
mesh = p3.plot_surface(X, Z, Y, color=color[...,0:3])
p3.show()



In [ ]: