ipyvolume icon indicating copy to clipboard operation
ipyvolume copied to clipboard

interactive colormap with Mesh object

Open patquem opened this issue 5 years ago • 1 comments

Hello, I have created a ColorMap class that I would like to be dynamically linked with ipyvolume objects (such as Mesh). My code below works, but for each ColorMap sliders event, a new mesh is in fact created. Is there a way to work with only one mesh object and update only the mesh color ? Patrick

cmap1 = ColorMap(left_color=[255,0,207], right_color=[0,0,255], curser_pos=65) # pre-setted colormap : purple -> blue
cmap1.show()

# Height map generation
x = y = np.arange(-3.0, 3.0, 0.025, dtype=np.float32)
X, Y = np.meshgrid(x, y)
Z1 = np.exp(-X**2 - Y**2)

def surf1(**kwargs):
    colormap=ListedColormap(cmap1.cmap)
    znorm = Z1 - Z1.min()
    znorm /= znorm.ptp()
    ipv.plot_surface(X, Z1, Y, color=colormap(znorm)[...,:3])
   
ipv.show()
widgets.interactive_output(surf1, cmap1.observer)

image

patquem avatar Apr 30 '21 08:04 patquem

Nice work. Yes, only create the object once, and modify the color attribute:

mesh = ipv.plot_surface(X, Z1, Y, color=colormap(znorm)[...,:3])
...
def event_handler():
  mesh.color = ..

Does that help? Cheers,

Maarten

maartenbreddels avatar Oct 29 '21 18:10 maartenbreddels