Skip to content

Commit 8b8626d

Browse files
committed
basics of other features works with ScatterStack for colors, markers, sizes, need to keep testing
1 parent a1e2995 commit 8b8626d

5 files changed

Lines changed: 192 additions & 100 deletions

File tree

fastplotlib/graphics/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from .mesh import MeshGraphic, SurfaceGraphic, PolygonGraphic
88
from .text import TextGraphic
99
from .line_collection import LineCollection, LineStack
10-
from .scatter_collection import ScatterCollection
10+
from .scatter_collection import ScatterCollection, ScatterStack
1111

1212
__all__ = [
1313
"Graphic",
@@ -23,4 +23,5 @@
2323
"LineCollection",
2424
"LineStack",
2525
"ScatterCollection",
26+
"ScatterStack",
2627
]

fastplotlib/graphics/features/_scatter.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def searchsorted_markers_to_int_array(markers_str_array: np.ndarray[str]):
100100
return marker_int_searchsorted_vals[indices]
101101

102102

103-
def parse_markers_init(markers: str | Sequence[str] | np.ndarray, n_datapoints: int):
103+
def parse_markers(markers: str | Sequence[str] | np.ndarray, n_datapoints: int):
104104
# first validate then allocate buffers
105105

106106
if isinstance(markers, str):
@@ -155,7 +155,7 @@ def __init__(
155155
Manages the markers buffer for the scatter points. Supports fancy indexing.
156156
"""
157157

158-
markers_int_array, self._markers_readable_array = parse_markers_init(
158+
markers_int_array, self._markers_readable_array = parse_markers(
159159
markers, n_datapoints
160160
)
161161

@@ -205,7 +205,7 @@ def set_value(self, graphic, value):
205205
if isinstance(value, (np.ndarray, list, tuple)):
206206
if self.buffer.data.shape[0] != len(value):
207207
# need to create a new buffer
208-
markers_int_array, self._markers_readable_array = parse_markers_init(
208+
markers_int_array, self._markers_readable_array = parse_markers(
209209
value, len(value)
210210
)
211211

fastplotlib/graphics/scatter_collection.py

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ def cmap(self, args):
102102

103103
class ScatterCollectionIndexer(CollectionIndexer, _ScatterCollectionProperties):
104104
"""Indexer for scatter collections"""
105-
106105
pass
107106

108107

@@ -117,11 +116,14 @@ def __init__(
117116
cmap: Sequence[str] | str = None,
118117
cmap_transform: np.ndarray | List = None,
119118
sizes: float | Sequence[float] = 5.0,
119+
uniform_size: bool = True,
120+
markers: np.ndarray | Sequence[str] = None,
121+
uniform_marker: bool = True,
122+
edge_width: float = 1.0,
120123
name: str = None,
121124
names: list[str] = None,
122125
metadata: Any = None,
123126
metadatas: Sequence[Any] | np.ndarray = None,
124-
kwargs_lines: list[dict] = None,
125127
**kwargs,
126128
):
127129
"""
@@ -186,13 +188,6 @@ def __init__(
186188
f"len(metadata) != len(data)\n{len(metadatas)} != {len(data)}"
187189
)
188190

189-
if kwargs_lines is not None:
190-
if len(kwargs_lines) != len(data):
191-
raise ValueError(
192-
f"len(kwargs_lines) != len(data)\n"
193-
f"{len(kwargs_lines)} != {len(data)}"
194-
)
195-
196191
self._cmap_transform = cmap_transform
197192
self._cmap_str = cmap
198193

@@ -259,9 +254,6 @@ def __init__(
259254
"or must be a tuple/list of colors represented by a string with the same length as the data"
260255
)
261256

262-
if kwargs_lines is None:
263-
kwargs_lines = dict()
264-
265257
self._set_world_object(pygfx.Group())
266258

267259
for i, d in enumerate(data):
@@ -286,14 +278,34 @@ def __init__(
286278
else:
287279
_name = None
288280

281+
if markers is not None:
282+
if isinstance(markers, (tuple, list, np.ndarray)):
283+
markers_ = markers[i]
284+
else:
285+
markers_ = markers
286+
else:
287+
markers_ = "o"
288+
289+
if sizes is not None:
290+
if isinstance(sizes, (tuple, list, np.ndarray)):
291+
sizes_ = sizes[i]
292+
else:
293+
sizes_ = sizes
294+
else:
295+
sizes_ = 5
296+
289297
lg = ScatterGraphic(
290298
data=d,
291299
colors=_c,
292-
sizes=sizes,
300+
sizes=sizes_,
301+
markers=markers_,
293302
cmap=_cmap,
294303
name=_name,
295304
metadata=_m,
296-
**kwargs_lines,
305+
uniform_marker=uniform_marker,
306+
uniform_size=uniform_size,
307+
edge_width=edge_width,
308+
**kwargs,
297309
)
298310

299311
self.add_graphic(lg)
@@ -519,19 +531,16 @@ def _get_linear_selector_init_args(self, axis, padding):
519531
class ScatterStack(ScatterCollection):
520532
def __init__(
521533
self,
522-
data: List[np.ndarray],
523-
thickness: float | Iterable[float] = 2.0,
524-
colors: str | Iterable[str] | np.ndarray | Iterable[np.ndarray] = "w",
525-
cmap: Iterable[str] | str = None,
534+
data: np.ndarray | List[np.ndarray],
535+
colors: str | Sequence[str] | np.ndarray | Sequence[np.ndarray] = "w",
536+
cmap: Sequence[str] | str = None,
526537
cmap_transform: np.ndarray | List = None,
527538
name: str = None,
528539
names: list[str] = None,
529540
metadata: Any = None,
530541
metadatas: Sequence[Any] | np.ndarray = None,
531-
isolated_buffer: bool = True,
532542
separation: float = 0.0,
533543
separation_axis: str = "y",
534-
kwargs_lines: list[dict] = None,
535544
**kwargs,
536545
):
537546
"""
@@ -584,26 +593,19 @@ def __init__(
584593
separation_axis: str, default "y"
585594
axis in which the line graphics in the stack should be separated
586595
587-
588-
kwargs_lines: list[dict], optional
589-
list of kwargs passed to the individual lines, ``len(kwargs_lines)`` must equal ``len(data)``
590-
591596
kwargs_collection
592597
kwargs for the collection, passed to GraphicCollection
593598
594599
"""
595600
super().__init__(
596601
data=data,
597-
thickness=thickness,
598602
colors=colors,
599603
cmap=cmap,
600604
cmap_transform=cmap_transform,
601605
name=name,
602606
names=names,
603607
metadata=metadata,
604608
metadatas=metadatas,
605-
isolated_buffer=isolated_buffer,
606-
kwargs_lines=kwargs_lines,
607609
**kwargs,
608610
)
609611

0 commit comments

Comments
 (0)