.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "_gallery/controllers/partial_camera_linking.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr__gallery_controllers_partial_camera_linking.py: Partial camera linking ====================== You can customize the camera axes that a controller acts on. In this example with two subplots you can pan and zoom in x-y in each individual subplot, but only the x-axis panning is linked between the two subplots. The y-axis pan and zoom in independent on each subplot. .. GENERATED FROM PYTHON SOURCE LINES 9-55 .. image-sg:: /_gallery/controllers/images/sphx_glr_partial_camera_linking_001.webp :alt: partial camera linking :srcset: /_gallery/controllers/images/sphx_glr_partial_camera_linking_001.webp :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none /home/runner/work/fastplotlib/fastplotlib/fastplotlib/graphics/features/_base.py:18: UserWarning: casting float64 array to float32 warn(f"casting {array.dtype} array to float32") | .. code-block:: Python # test_example = false 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])) for subplot in figure: subplot.camera.zoom = 1.0 figure.show(maintain_aspect=False, autoscale=True) # NOTE: fpl.loop.run() should not be used for interactive sessions # See the "JupyterLab and IPython" section in the user guide if __name__ == "__main__": print(__doc__) fpl.loop.run() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.406 seconds) .. _sphx_glr_download__gallery_controllers_partial_camera_linking.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: partial_camera_linking.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: partial_camera_linking.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_