.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "11_demos\itom\plots\demoInteractiveShapePicker.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_11_demos_itom_plots_demoInteractiveShapePicker.py: Interactive shape picker =========================== This demo shows how to let the user select a certain number of shapes in a plot. The shapes are then returned as list of shapes. This list can also be assigned to the ``geometricShapes`` property of any other plot to display them in another plot. The ``plotItem.drawAndPickElements`` method is used for this demo. It accepts any kind of shape (``plotItem.Primitive`` ...) besides ``plotItem.PrimitiveMultiPointPick``. Use instead ``PrimitivePoint`` or use the similar method ``plotItem.pickPoints`` if the user should select a arbitrary number of single points. .. GENERATED FROM PYTHON SOURCE LINES 17-53 .. code-block:: default from itom import dataObject from itom import plot from itom import shape from itom import ui from itom import plotItem from typing import Tuple elementList = [ (plotItem.PrimitivePoint, 5), (plotItem.PrimitiveCircle, 3), (plotItem.PrimitivePolygon, 2), (plotItem.PrimitiveLine, 1) ] for shapeType, numShapes in elementList: img = dataObject.zeros([100, 150], "float32") for r in range(img.shape[0]): img[r, :] = (r % 20) * 0.02 [i, h] = plot(img) try: polygons: Tuple[shape] = h.drawAndPickElements(shapeType, numShapes) except RuntimeError as ex: print(str(ex)) ui.msgWarning("Abort", "The user interaction has been aborted") break else: print("The following shapes have been selected:\n--------------------") for p in polygons: print(str(p)) print("---------------------") .. GENERATED FROM PYTHON SOURCE LINES 55-57 .. image:: ../../_static/demoInteractiveShapePicker_1.png :width: 100% .. GENERATED FROM PYTHON SOURCE LINES 59-61 .. image:: ../../_static/demoInteractiveShapePicker_2.png :width: 100% .. GENERATED FROM PYTHON SOURCE LINES 63-65 .. image:: ../../_static/demoInteractiveShapePicker_3.png :width: 100% .. GENERATED FROM PYTHON SOURCE LINES 67-69 .. image:: ../../_static/demoInteractiveShapePicker_4.png :width: 100% .. _sphx_glr_download_11_demos_itom_plots_demoInteractiveShapePicker.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: demoInteractiveShapePicker.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: demoInteractiveShapePicker.ipynb `