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 b9cc2ec

Browse filesBrowse files
authored
Create partial_camera_linking.py (#1020)
1 parent 4a13244 commit b9cc2ec
Copy full SHA for b9cc2ec

1 file changed

+55Lines changed: 55 additions & 0 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file
+55Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
"""
2+
Partial camera linking
3+
======================
4+
5+
You can customize the camera axes that a controller acts on. In this example with two subplots you can pan and zoom
6+
in x-y in each individual subplot, but only the x-axis panning is linked between the two subplots. The y-axis pan
7+
and zoom in independent on each subplot.
8+
"""
9+
10+
# test_example = false
11+
# sphinx_gallery_pygfx_docs = 'screenshot'
12+
13+
import numpy as np
14+
import fastplotlib as fpl
15+
import pygfx
16+
17+
xs = np.linspace(0, 2 * np.pi, 100)
18+
ys = np.sin(xs)
19+
20+
ys_big = np.random.rand(100) * 10
21+
22+
# create cameras, fov=0 means Orthographic projection
23+
camera1 = pygfx.PerspectiveCamera(fov=0)
24+
camera2 = pygfx.PerspectiveCamera(fov=0)
25+
26+
# create controllers, first add the "main" camera for the subplot
27+
controller1 = pygfx.PanZoomController(camera1)
28+
controller2 = pygfx.PanZoomController(camera2)
29+
30+
# add the other camera to each controller, but only include the 'x' state, i.e. 'y' for height is not included
31+
# this must be done only after adding the "main" cameras to the controller as done above
32+
controller1.add_camera(camera2, include_state={"x", "width"})
33+
controller2.add_camera(camera1, include_state={"x", "width"})
34+
35+
# create figure using these cameras and controllers
36+
figure = fpl.Figure(
37+
shape=(2, 1),
38+
cameras=[camera1, camera2],
39+
controllers=[controller1, controller2],
40+
size=(700, 560)
41+
)
42+
43+
figure[0, 0].add_line(np.column_stack([xs, ys_big]))
44+
figure[1, 0].add_line(np.column_stack([xs, ys]))
45+
46+
for subplot in figure:
47+
subplot.camera.zoom = 1.0
48+
49+
figure.show(maintain_aspect=False, autoscale=True)
50+
51+
# NOTE: fpl.loop.run() should not be used for interactive sessions
52+
# See the "JupyterLab and IPython" section in the user guide
53+
if __name__ == "__main__":
54+
print(__doc__)
55+
fpl.loop.run()

0 commit comments

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