-
Notifications
You must be signed in to change notification settings - Fork 64
Expand file tree
/
Copy pathscatter.py
More file actions
101 lines (75 loc) · 3.15 KB
/
scatter.py
File metadata and controls
101 lines (75 loc) · 3.15 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
from typing import *
import numpy as np
import pygfx
from ..utils import parse_cmap_values
from ._base import Graphic
from ._features import PointsDataFeature, ColorFeature, CmapFeature, PointsSizesFeature
class ScatterGraphic(Graphic):
features = {"data", "sizes", "colors", "cmap", "present"}
def __init__(
self,
data: np.ndarray,
sizes: Union[int, float, np.ndarray, list] = 1,
colors: np.ndarray = "w",
alpha: float = 1.0,
cmap: str = None,
cmap_values: Union[np.ndarray, List] = None,
z_position: float = 0.0,
*args,
**kwargs,
):
"""
Create a Scatter Graphic, 2d or 3d
Parameters
----------
data: array-like
Scatter data to plot, 2D must be of shape [n_points, 2], 3D must be of shape [n_points, 3]
sizes: float or iterable of float, optional, default 1.0
size of the scatter points
colors: str, array, or iterable, default "w"
specify colors as a single human readable string, a single RGBA array,
or an iterable of strings or RGBA arrays
cmap: str, optional
apply a colormap to the scatter instead of assigning colors manually, this
overrides any argument passed to "colors"
cmap_values: 1D array-like or list of numerical values, optional
if provided, these values are used to map the colors from the cmap
alpha: float, optional, default 1.0
alpha value for the colors
z_position: float, optional
z-axis position for placing the graphic
args
passed to Graphic
kwargs
passed to Graphic
Features
--------
**data**: :class:`.ImageDataFeature`
Manages the line [x, y, z] positions data buffer, allows regular and fancy indexing.
**colors**: :class:`.ColorFeature`
Manages the color buffer, allows regular and fancy indexing.
**cmap**: :class:`.CmapFeature`
Manages the cmap, wraps :class:`.ColorFeature` to add additional functionality relevant to cmaps.
**present**: :class:`.PresentFeature`
Control the presence of the Graphic in the scene, set to ``True`` or ``False``
"""
self.data = PointsDataFeature(self, data)
n_datapoints = self.data().shape[0]
if cmap is not None:
colors = parse_cmap_values(
n_colors=n_datapoints, cmap_name=cmap, cmap_values=cmap_values
)
self.colors = ColorFeature(self, colors, n_colors=n_datapoints, alpha=alpha)
self.cmap = CmapFeature(
self, self.colors(), cmap_name=cmap, cmap_values=cmap_values
)
self.sizes = PointsSizesFeature(self, sizes)
super().__init__(*args, **kwargs)
world_object = pygfx.Points(
pygfx.Geometry(
positions=self.data(), sizes=self.sizes(), colors=self.colors()
),
material=pygfx.PointsMaterial(color_mode="vertex", size_mode="vertex"),
)
self._set_world_object(world_object)
self.position_z = z_position