Note
Go to the end to download the full example code.
Spheres and Sticks#
Draw spherical Markers with Tube meshes connecting them.
import numpy as np
from vispy import app, scene
# Create canvas and view
canvas = scene.SceneCanvas(keys='interactive', size=(600, 600), show=True)
view = canvas.central_widget.add_view()
view.camera = scene.cameras.ArcballCamera(fov=0)
view.camera.scale_factor = 500
# Prepare data
np.random.seed(57983)
data = np.random.normal(size=(40, 3), loc=0, scale=100)
size = np.random.rand(40) * 100
colors = np.random.rand(40, 3)
data = np.concatenate([data, [[0, 0, 0]]], axis=0)
size = np.concatenate([size, [100]], axis=0)
colors = np.concatenate([colors, [[1, 0, 0]]], axis=0)
# Create and show visual
vis = scene.visuals.Markers(
pos=data,
size=100,
antialias=0,
face_color=colors,
edge_color='white',
edge_width=0,
scaling=True,
spherical=True,
)
vis.parent = view.scene
lines = np.array([[data[i], data[-1]]
for i in range(len(data) - 1)])
line_vis = []
for line in lines:
vis2 = scene.visuals.Tube(line, radius=5)
vis2.parent = view.scene
line_vis.append(vis2)
if __name__ == "__main__":
app.run()
Total running time of the script: (0 minutes 1.675 seconds)