.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "_gallery/misc/cursor_transform.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_misc_cursor_transform.py: Cursor transform ================ Create a cursor and add them to subplots with a transform function. A common usecase is image registration. .. GENERATED FROM PYTHON SOURCE LINES 7-54 .. image-sg:: /_gallery/misc/images/sphx_glr_cursor_transform_001.webp :alt: cursor transform :srcset: /_gallery/misc/images/sphx_glr_cursor_transform_001.webp :class: sphx-glr-single-img .. code-block:: Python # test_example = False import numpy as np import fastplotlib as fpl import imageio.v3 as iio # get an image img1 = iio.imread("imageio:camera.png") # create another image, but it is offset img2 = np.zeros(img1.shape) img2[50:, 20:] = img1[:-50, :-20] figure = fpl.Figure((1, 2), size=(700, 450)) # add images figure[0, 0].add_image(img1) figure[0, 1].add_image(img2) # create cursor cursor = fpl.Cursor("crosshair") # add first subplot to cursor cursor.add_subplot(figure[0, 0]) # a transform function for subplot 2 to indicate that the data is shifted def transform_func(pos): return (pos[0] + 20, pos[1] + 50) # add second subplot with a transform cursor.add_subplot(figure[0, 1], transform=transform_func) figure.show() # you can programmatically set cursor position cursor.position = (400, 120) # you can hide the canvas cursor, this is different and has nothing to do with the fastplotlib Cursor! figure.canvas.set_cursor("none") # 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.949 seconds) .. _sphx_glr_download__gallery_misc_cursor_transform.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: cursor_transform.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: cursor_transform.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_