.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "_gallery/selection_tools/rectangle_selector_zoom.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_selection_tools_rectangle_selector_zoom.py: Rectangle Selectors Images ========================== Example showing how to use a `RectangleSelector` with images .. GENERATED FROM PYTHON SOURCE LINES 7-53 .. image-sg:: /_gallery/selection_tools/images/sphx_glr_rectangle_selector_zoom_001.webp :alt: rectangle selector zoom :srcset: /_gallery/selection_tools/images/sphx_glr_rectangle_selector_zoom_001.webp :class: sphx-glr-single-img .. code-block:: Python # test_example = false import imageio.v3 as iio import fastplotlib as fpl # create a figure figure = fpl.Figure( shape=(2, 1), size=(700, 560) ) # add image image_graphic = figure[0, 0].add_image(data=iio.imread("imageio:camera.png")) # add rectangle selector to image graphic rectangle_selector = image_graphic.add_rectangle_selector() # add a zoomed plot of the selected data zoom_ig = figure[1, 0].add_image(rectangle_selector.get_selected_data()) # add event handler to update the data of the zoomed image as the selection changes @rectangle_selector.add_event_handler("selection") def update_data(ev): # get the new data new_data = ev.get_selected_data() # remove the old zoomed image graphic global zoom_ig figure[1, 0].remove_graphic(zoom_ig) # add new zoomed image of new data zoom_ig = figure[1, 0].add_image(data=new_data) # autoscale the plot figure[1, 0].auto_scale() figure.show() # NOTE: `if __name__ == "__main__"` is NOT how to use fastplotlib interactively # please see our docs for using fastplotlib interactively in ipython and jupyter if __name__ == "__main__": print(__doc__) fpl.run() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 1.462 seconds) .. _sphx_glr_download__gallery_selection_tools_rectangle_selector_zoom.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: rectangle_selector_zoom.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: rectangle_selector_zoom.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: rectangle_selector_zoom.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_