ipyvolume icon indicating copy to clipboard operation
ipyvolume copied to clipboard

Unexpected scatter behaviour

Open sitzikbs opened this issue 3 years ago • 0 comments

Hi, I am trying to visualize a sequence of point clouds with an interactive slider to switch between one point cloud to the next. I have observed weird jittering behaviour (even when setting animation to 0).

Attached below is a minimum working example (sampled random points on a sphere). When moving the slider the points "jump around". My assumption is that the update for x, y, z coordinates is not synchronized. Is this the desired behaviour? and if so, how can one sync the update?


import numpy as np
import ipyvolume as ipv

# Generate random points on a sphere
phi = np.linspace(0, np.pi, 200)
theta = np.linspace(0, 2 * np.pi, 200)
xx = np.outer(np.sin(theta), np.cos(phi))
yy = np.outer(np.sin(theta), np.sin(phi))
zz = np.outer(np.cos(theta), np.ones_like(phi))

# Shuffle and stack the points
pc_data = []
for i in range(20):
    points = np.stack([xx.flatten(), yy.flatten(), zz.flatten()], 1)
    np.random.shuffle(points)
    pc_data.append( points  + i/20 )

#plot
class Scene():
    def __init__(self):
        self.fig_h = ipv.figure(animation=0, animation_exponent=0)
        x, y, z = pc_data[0][:, 0], pc_data[0][:, 1], pc_data[0][:, 2]

        self.scatter_h = ipv.pylab.scatter(x, y,z, size=1, marker="sphere", color='red')
        ipv.pylab.xyzlim(-1, 1)
        ipv.style.use('minimal')
        ipv.show()
        self.ui = widgets.interact(self.update, ind=(0,len(pc_data)-1))
        
    def update(self, ind):
        self.fig_h.animation=0
        x, y, z = pc_data[ind][:, 0], pc_data[ind][:, 1], pc_data[ind][:, 2]
        [self.scatter_h.x, self.scatter_h.y, self.scatter_h.z] = [x, y, z]

 
scene = Scene()

sitzikbs avatar Mar 05 '21 06:03 sitzikbs