-
Notifications
You must be signed in to change notification settings - Fork 62
Closed
Description
Not sure why, pygfx demo works, fpl is doing something additional I think:
import numpy as np
import fastplotlib as fpl
import pygfx
xs = np.linspace(0, 2 * np.pi, 100)
ys = np.sin(xs)
ys_big = np.random.rand(100) * 10
# create cameras, fov=0 means Orthographic projection
camera1 = pygfx.PerspectiveCamera(fov=0)
camera2 = pygfx.PerspectiveCamera(fov=0)
# create controllers, first add the "main" camera for the subplot
controller1 = pygfx.PanZoomController(camera1)
controller2 = pygfx.PanZoomController(camera2)
# add the other camera to each controller, but only include the 'x' state, i.e. 'y' for height is not included
# this must be done only after adding the "main" cameras to the controller as done above
controller1.add_camera(camera2, include_state={"x", "width"})
controller2.add_camera(camera1, include_state={"x", "width"})
# create figure using these cameras and controllers
figure = fpl.Figure(
shape=(2, 1),
cameras=[camera1, camera2],
controllers=[controller1, controller2],
size=(700, 560)
)
figure[0, 0].add_line(np.column_stack([xs, ys_big]))
figure[1, 0].add_line(np.column_stack([xs, ys]))
print(controller1._cameras)
print(controller2._cameras)
for subplot in figure:
subplot.camera.zoom = 1.0
figure.show(maintain_aspect=False, autoscale=False)I did make the following change to PlotArea:
Index: fastplotlib/layouts/_plot_area.py
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/fastplotlib/layouts/_plot_area.py b/fastplotlib/layouts/_plot_area.py
--- a/fastplotlib/layouts/_plot_area.py
+++ b/fastplotlib/layouts/_plot_area.py (date 1743405901011)
@@ -79,7 +79,9 @@
self._camera = camera
self._controller = controller
- self.controller.add_camera(self._camera)
+ if self.camera not in self.controller.cameras:
+ self.controller.add_camera(self._camera)
+
self.controller.register_events(
self.viewport,
)Metadata
Metadata
Assignees
Labels
No labels