File: marker_spheres.py

package info (click to toggle)
python-vispy 0.15.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 8,868 kB
  • sloc: python: 59,799; javascript: 6,800; makefile: 69; sh: 6
file content (56 lines) | stat: -rw-r--r-- 1,516 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# -*- coding: utf-8 -*-
# vispy: gallery 2
# -----------------------------------------------------------------------------
# Copyright (c) Vispy Development Team. All Rights Reserved.
# Distributed under the (new) BSD License. See LICENSE.txt for more info.
# -----------------------------------------------------------------------------
"""
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()