Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 598dd8b

Browse filesBrowse files
committed
proof of concept
1 parent 29b098d commit 598dd8b
Copy full SHA for 598dd8b

File tree

Expand file treeCollapse file tree

7 files changed

+212
-45
lines changed
Filter options
Expand file treeCollapse file tree

7 files changed

+212
-45
lines changed
+24Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import numpy as np
2+
import fastplotlib as fpl
3+
4+
5+
xs = np.linspace(0, 10 * np.pi, 1000)
6+
ys = np.sin(xs)
7+
8+
ys100 = ys * 1000
9+
10+
l1 = np.column_stack([xs, ys])
11+
l2 = np.column_stack([xs, ys100])
12+
13+
fig = fpl.Figure(size=(500, 400))
14+
15+
fig[0, 0].add_line(l1)
16+
fig.show(maintain_aspect=False)
17+
fig[0, 0].auto_scale(zoom=0.4)
18+
19+
rs = fig[0, 0].add_reference_space(scale=(1, 500, 1))
20+
l2 = fig[0, 0].add_line(l2, reference_space=rs, colors="r")
21+
l2.add_axes(rs)
22+
l2.axes.y.line.material.color = "r"
23+
24+
fpl.loop.run()

‎fastplotlib/graphics/_axes.py

Copy file name to clipboardExpand all lines: fastplotlib/graphics/_axes.py
+24-24Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def yz(self) -> Grid:
144144
class Axes:
145145
def __init__(
146146
self,
147-
plot_area,
147+
reference_space,
148148
intersection: tuple[int, int, int] | None = None,
149149
x_kwargs: dict = None,
150150
y_kwargs: dict = None,
@@ -157,7 +157,7 @@ def __init__(
157157
[[1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0]]
158158
),
159159
):
160-
self._plot_area = plot_area
160+
self._reference_space = reference_space
161161

162162
if x_kwargs is None:
163163
x_kwargs = dict()
@@ -193,20 +193,20 @@ def __init__(
193193
self.x.end_pos = 100, 0, 0
194194
self.x.start_value = self.x.start_pos[0] - offset[0]
195195
statsx = self.x.update(
196-
self._plot_area.camera, self._plot_area.viewport.logical_size
196+
self._reference_space.camera, self._reference_space.viewport.logical_size
197197
)
198198

199199
self.y.start_pos = 0, 0, 0
200200
self.y.end_pos = 0, 100, 0
201201
self.y.start_value = self.y.start_pos[1] - offset[1]
202202
statsy = self.y.update(
203-
self._plot_area.camera, self._plot_area.viewport.logical_size
203+
self._reference_space.camera, self._reference_space.viewport.logical_size
204204
)
205205

206206
self.z.start_pos = 0, 0, 0
207207
self.z.end_pos = 0, 0, 100
208208
self.z.start_value = self.z.start_pos[1] - offset[2]
209-
self.z.update(self._plot_area.camera, self._plot_area.viewport.logical_size)
209+
self.z.update(self._reference_space.camera, self._reference_space.viewport.logical_size)
210210

211211
# world object for the rulers + grids
212212
self._world_object = pygfx.Group()
@@ -219,7 +219,7 @@ def __init__(
219219
)
220220

221221
# set z ruler invisible for orthographic projections for now
222-
if self._plot_area.camera.fov == 0:
222+
if self._reference_space.camera.fov == 0:
223223
# TODO: allow any orientation in the future even for orthographic projections
224224
self.z.visible = False
225225

@@ -251,7 +251,7 @@ def __init__(
251251
self._grids = Grids(**_grids)
252252
self.world_object.add(self._grids)
253253

254-
if self._plot_area.camera.fov == 0:
254+
if self._reference_space.camera.fov == 0:
255255
# orthographic projection, place grids far away
256256
self._grids.local.z = -1000
257257

@@ -382,13 +382,13 @@ def update_using_bbox(self, bbox):
382382
"""
383383

384384
# flip axes if camera scale is flipped
385-
if self._plot_area.camera.local.scale_x < 0:
385+
if self._reference_space.camera.local.scale_x < 0:
386386
bbox[0, 0], bbox[1, 0] = bbox[1, 0], bbox[0, 0]
387387

388-
if self._plot_area.camera.local.scale_y < 0:
388+
if self._reference_space.camera.local.scale_y < 0:
389389
bbox[0, 1], bbox[1, 1] = bbox[1, 1], bbox[0, 1]
390390

391-
if self._plot_area.camera.local.scale_z < 0:
391+
if self._reference_space.camera.local.scale_z < 0:
392392
bbox[0, 2], bbox[1, 2] = bbox[1, 2], bbox[0, 2]
393393

394394
if self.intersection is None:
@@ -413,8 +413,8 @@ def update_using_camera(self):
413413
if not self.visible:
414414
return
415415

416-
if self._plot_area.camera.fov == 0:
417-
xpos, ypos, width, height = self._plot_area.viewport.rect
416+
if self._reference_space.camera.fov == 0:
417+
xpos, ypos, width, height = self._reference_space.viewport.rect
418418
# orthographic projection, get ranges using inverse
419419

420420
# get range of screen space by getting the corners
@@ -442,8 +442,8 @@ def update_using_camera(self):
442442
# self.y.local.rotation
443443
# )
444444

445-
min_vals = self._plot_area.map_screen_to_world((xmin, ymin))
446-
max_vals = self._plot_area.map_screen_to_world((xmax, ymax))
445+
min_vals = self._reference_space.map_screen_to_world((xmin, ymin))
446+
max_vals = self._reference_space.map_screen_to_world((xmax, ymax))
447447

448448
if min_vals is None or max_vals is None:
449449
return
@@ -462,14 +462,14 @@ def update_using_camera(self):
462462

463463
else:
464464
# set ruler start and end positions based on scene bbox
465-
bbox = self._plot_area._fpl_graphics_scene.get_world_bounding_box()
465+
bbox = self._reference_space._fpl_graphics_scene.get_world_bounding_box()
466466

467467
if self.intersection is None:
468-
if self._plot_area.camera.fov == 0:
468+
if self._reference_space.camera.fov == 0:
469469
# place the ruler close to the left and bottom edges of the viewport
470470
# TODO: determine this for perspective projections
471471
xscreen_10, yscreen_10 = xpos + (width * 0.1), ypos + (height * 0.9)
472-
intersection = self._plot_area.map_screen_to_world(
472+
intersection = self._reference_space.map_screen_to_world(
473473
(xscreen_10, yscreen_10)
474474
)
475475
else:
@@ -502,15 +502,15 @@ def update(self, bbox, intersection):
502502
world_x_10, world_y_10, world_z_10 = intersection
503503

504504
# swap min and max for each dimension if necessary
505-
if self._plot_area.camera.local.scale_y < 0:
505+
if self._reference_space.camera.local.scale_y < 0:
506506
world_ymin, world_ymax = world_ymax, world_ymin
507507
self.y.tick_side = "right" # swap tick side
508508
self.x.tick_side = "right"
509509
else:
510510
self.y.tick_side = "left"
511511
self.x.tick_side = "right"
512512

513-
if self._plot_area.camera.local.scale_x < 0:
513+
if self._reference_space.camera.local.scale_x < 0:
514514
world_xmin, world_xmax = world_xmax, world_xmin
515515
self.x.tick_side = "left"
516516

@@ -519,24 +519,24 @@ def update(self, bbox, intersection):
519519

520520
self.x.start_value = self.x.start_pos[0] - self.offset[0]
521521
statsx = self.x.update(
522-
self._plot_area.camera, self._plot_area.viewport.logical_size
522+
self._reference_space.camera, self._reference_space.viewport.logical_size
523523
)
524524

525525
self.y.start_pos = world_x_10, world_ymin, world_z_10
526526
self.y.end_pos = world_x_10, world_ymax, world_z_10
527527

528528
self.y.start_value = self.y.start_pos[1] - self.offset[1]
529529
statsy = self.y.update(
530-
self._plot_area.camera, self._plot_area.viewport.logical_size
530+
self._reference_space.camera, self._reference_space.viewport.logical_size
531531
)
532532

533-
if self._plot_area.camera.fov != 0:
533+
if self._reference_space.camera.fov != 0:
534534
self.z.start_pos = world_x_10, world_y_10, world_zmin
535535
self.z.end_pos = world_x_10, world_y_10, world_zmax
536536

537537
self.z.start_value = self.z.start_pos[2] - self.offset[2]
538538
statsz = self.z.update(
539-
self._plot_area.camera, self._plot_area.viewport.logical_size
539+
self._reference_space.camera, self._reference_space.viewport.logical_size
540540
)
541541
major_step_z = statsz["tick_step"]
542542

@@ -546,7 +546,7 @@ def update(self, bbox, intersection):
546546
self.grids.xy.major_step = major_step_x, major_step_y
547547
self.grids.xy.minor_step = 0.2 * major_step_x, 0.2 * major_step_y
548548

549-
if self._plot_area.camera.fov != 0:
549+
if self._reference_space.camera.fov != 0:
550550
self.grids.xz.major_step = major_step_x, major_step_z
551551
self.grids.xz.minor_step = 0.2 * major_step_x, 0.2 * major_step_z
552552

‎fastplotlib/graphics/_base.py

Copy file name to clipboardExpand all lines: fastplotlib/graphics/_base.py
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -447,15 +447,15 @@ def rotate(self, alpha: float, axis: Literal["x", "y", "z"] = "y"):
447447
def axes(self) -> Axes:
448448
return self._axes
449449

450-
def add_axes(self):
450+
def add_axes(self, reference_frame):
451451
"""Add axes onto this Graphic"""
452452
if self._axes is not None:
453453
raise AttributeError("Axes already added onto this graphic")
454454

455-
self._axes = Axes(self._plot_area, offset=self.offset, grids=False)
455+
self._axes = Axes(reference_frame, offset=self.offset, grids=False)
456456
self._axes.world_object.local.rotation = self.world_object.local.rotation
457457

458-
self._plot_area.scene.add(self.axes.world_object)
458+
reference_frame.scene.add(self.axes.world_object)
459459
self._axes.update_using_bbox(self.world_object.get_world_bounding_box())
460460

461461
@property

‎fastplotlib/layouts/_graphic_methods_mixin.py

Copy file name to clipboardExpand all lines: fastplotlib/layouts/_graphic_methods_mixin.py
+18-13Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,16 @@ def _create_graphic(self, graphic_class, *args, **kwargs) -> Graphic:
1515
else:
1616
center = False
1717

18+
if "reference_space" in kwargs.keys():
19+
reference_space = kwargs.pop("reference_space")
20+
else:
21+
reference_space = 0
22+
1823
if "name" in kwargs.keys():
1924
self._check_graphic_name_exists(kwargs["name"])
2025

2126
graphic = graphic_class(*args, **kwargs)
22-
self.add_graphic(graphic, center=center)
27+
self.add_graphic(graphic, center=center, reference_space=reference_space)
2328

2429
return graphic
2530

@@ -32,7 +37,7 @@ def add_image(
3237
interpolation: str = "nearest",
3338
cmap_interpolation: str = "linear",
3439
isolated_buffer: bool = True,
35-
**kwargs,
40+
**kwargs
3641
) -> ImageGraphic:
3742
"""
3843
@@ -78,7 +83,7 @@ def add_image(
7883
interpolation,
7984
cmap_interpolation,
8085
isolated_buffer,
81-
**kwargs,
86+
**kwargs
8287
)
8388

8489
def add_line_collection(
@@ -96,7 +101,7 @@ def add_line_collection(
96101
metadatas: Union[Sequence[Any], numpy.ndarray] = None,
97102
isolated_buffer: bool = True,
98103
kwargs_lines: list[dict] = None,
99-
**kwargs,
104+
**kwargs
100105
) -> LineCollection:
101106
"""
102107
@@ -169,7 +174,7 @@ def add_line_collection(
169174
metadatas,
170175
isolated_buffer,
171176
kwargs_lines,
172-
**kwargs,
177+
**kwargs
173178
)
174179

175180
def add_line(
@@ -183,7 +188,7 @@ def add_line(
183188
cmap_transform: Union[numpy.ndarray, Iterable] = None,
184189
isolated_buffer: bool = True,
185190
size_space: str = "screen",
186-
**kwargs,
191+
**kwargs
187192
) -> LineGraphic:
188193
"""
189194
@@ -234,7 +239,7 @@ def add_line(
234239
cmap_transform,
235240
isolated_buffer,
236241
size_space,
237-
**kwargs,
242+
**kwargs
238243
)
239244

240245
def add_line_stack(
@@ -253,7 +258,7 @@ def add_line_stack(
253258
separation: float = 10.0,
254259
separation_axis: str = "y",
255260
kwargs_lines: list[dict] = None,
256-
**kwargs,
261+
**kwargs
257262
) -> LineStack:
258263
"""
259264
@@ -334,7 +339,7 @@ def add_line_stack(
334339
separation,
335340
separation_axis,
336341
kwargs_lines,
337-
**kwargs,
342+
**kwargs
338343
)
339344

340345
def add_scatter(
@@ -349,7 +354,7 @@ def add_scatter(
349354
sizes: Union[float, numpy.ndarray, Iterable[float]] = 1,
350355
uniform_size: bool = False,
351356
size_space: str = "screen",
352-
**kwargs,
357+
**kwargs
353358
) -> ScatterGraphic:
354359
"""
355360
@@ -409,7 +414,7 @@ def add_scatter(
409414
sizes,
410415
uniform_size,
411416
size_space,
412-
**kwargs,
417+
**kwargs
413418
)
414419

415420
def add_text(
@@ -422,7 +427,7 @@ def add_text(
422427
screen_space: bool = True,
423428
offset: tuple[float] = (0, 0, 0),
424429
anchor: str = "middle-center",
425-
**kwargs,
430+
**kwargs
426431
) -> TextGraphic:
427432
"""
428433
@@ -473,5 +478,5 @@ def add_text(
473478
screen_space,
474479
offset,
475480
anchor,
476-
**kwargs,
481+
**kwargs
477482
)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.