.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples\region_of_interest\SpanROI_interactive_sum.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_auto_examples_region_of_interest_SpanROI_interactive_sum.py: Interactive integration of one dimensional signal ================================================= This example shows how to integrate a signal using an interactive ROI. .. GENERATED FROM PYTHON SOURCE LINES 8-11 .. code-block:: Python import hyperspy.api as hs .. GENERATED FROM PYTHON SOURCE LINES 12-13 Create a signal: .. GENERATED FROM PYTHON SOURCE LINES 13-15 .. code-block:: Python s = hs.data.two_gaussians() .. GENERATED FROM PYTHON SOURCE LINES 16-17 Create SpanROI: .. GENERATED FROM PYTHON SOURCE LINES 17-19 .. code-block:: Python roi = hs.roi.SpanROI(left=10, right=20) .. GENERATED FROM PYTHON SOURCE LINES 20-23 Slice signal with roi with the ROI. By using the `interactive` function, the output signal ``s_roi`` will update automatically. The ROI will be added automatically on the signal figure: .. GENERATED FROM PYTHON SOURCE LINES 23-28 .. code-block:: Python s.plot() sliced_signal = roi.interactive(s, axes=s.axes_manager.signal_axes) # Choose the second figure as gallery thumbnail: # sphinx_gallery_thumbnail_number = 2 .. rst-class:: sphx-glr-horizontal * .. image-sg:: /auto_examples/region_of_interest/images/sphx_glr_SpanROI_interactive_sum_001.png :alt: Two Gaussians Navigator :srcset: /auto_examples/region_of_interest/images/sphx_glr_SpanROI_interactive_sum_001.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/region_of_interest/images/sphx_glr_SpanROI_interactive_sum_002.png :alt: Two Gaussians Signal :srcset: /auto_examples/region_of_interest/images/sphx_glr_SpanROI_interactive_sum_002.png :class: sphx-glr-multi-img .. GENERATED FROM PYTHON SOURCE LINES 29-30 Create a placeholder signal for the integrated signal and set metadata: .. GENERATED FROM PYTHON SOURCE LINES 30-33 .. code-block:: Python integrated_sliced_signal = sliced_signal.sum(axis=-1).T integrated_sliced_signal.metadata.General.title = "Integrated intensity" .. GENERATED FROM PYTHON SOURCE LINES 34-37 Create the interactive computation, which will update when the ROI ``roi`` is changed. wWe use the ``out`` argument to place the results of the integration in the placeholder signal defined in the previous step: .. GENERATED FROM PYTHON SOURCE LINES 37-45 .. code-block:: Python hs.interactive( sliced_signal.sum, axis=sliced_signal.axes_manager.signal_axes, event=roi.events.changed, recompute_out_event=None, out=integrated_sliced_signal, ) .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 46-47 Plot the integrated sum signal: .. GENERATED FROM PYTHON SOURCE LINES 47-48 .. code-block:: Python integrated_sliced_signal.plot() .. image-sg:: /auto_examples/region_of_interest/images/sphx_glr_SpanROI_interactive_sum_003.png :alt: Integrated intensity Signal :srcset: /auto_examples/region_of_interest/images/sphx_glr_SpanROI_interactive_sum_003.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 1.529 seconds) .. _sphx_glr_download_auto_examples_region_of_interest_SpanROI_interactive_sum.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: SpanROI_interactive_sum.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: SpanROI_interactive_sum.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_