In [1]:
import numpy as np
import pymesh
import bqplot.pyplot as plt
In [2]:
points = np.random.randn(100, 2)
mesh = pymesh.Mesh(points)
In [3]:
lines = np.stack(simplex.lines() for simplex in mesh)
plt.figure()
plt.plot(lines[:,:,0],
lines[:,:,1],
close_path=True,
colors=['red'],
stroke_width=1)
plt.scatter(x=points[:,0],
y=points[:,1])
plt.show()
In [4]:
lines = np.stack(simplex.lines() for simplex in mesh)
def update_lines(change):
with simplices.hold_sync():
points = np.stack([scatter.x, scatter.y], axis=1)
mesh = pymesh.Mesh(points)
lines = np.stack(simplex.lines() for simplex in mesh)
simplices.x = lines[:,:,0]
simplices.y = lines[:,:,1]
plt.figure()
simplices = plt.plot(lines[:,:,0], lines[:,:,1], close_path=True, colors=['red'], stroke_width=1)
scatter = plt.scatter(x=points[:,0], y=points[:,1], enable_move=True)
plt.show()
scatter.observe(update_lines, names=['x', 'y'])
In [ ]: