.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/Markers/making_inset_images.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_Markers_making_inset_images.py: Making Inset Images =================== This example shows how to make images that overlay the main images. These can be images overlaid using some king of transparency or make an inset image. It can also be useful for something like making something like a circular color bar to show orientation. .. GENERATED FROM PYTHON SOURCE LINES 9-14 .. code-block:: Python import numpy as np import hyperspy.api as hs import matplotlib .. GENERATED FROM PYTHON SOURCE LINES 15-16 Making some artificial data .. GENERATED FROM PYTHON SOURCE LINES 16-20 .. code-block:: Python s = hs.signals.Signal2D(np.random.rand(100, 100, 10, 10)) signal2 = hs.signals.Signal2D(np.random.rand(10, 10)) .. GENERATED FROM PYTHON SOURCE LINES 21-22 Plotting signal2 as an inset image on s .. GENERATED FROM PYTHON SOURCE LINES 22-48 .. code-block:: Python signal2_shape = signal2.axes_manager._signal_shape_in_array y = np.linspace( -0.1, 0.1, signal2_shape[0] + 1 ) # making a mesh grid 20% of the size of the main image x = np.linspace( -0.1, 0.1, signal2_shape[1] + 1 ) # making a mesh grid 20% of the size of the main image xx, yy = np.meshgrid(x, y) coords = np.stack([xx, yy], axis=-1) quad = hs.plot.markers.Markers( collection=matplotlib.collections.QuadMesh, coordinates=coords, array=signal2.data, cmap="hsv", transform="axes", offset_transform="axes", offsets=[[0.7, 0.7]], alpha=1, ) # Put in top right corner s.plot() s.add_marker(quad) .. rst-class:: sphx-glr-horizontal * .. image-sg:: /auto_examples/Markers/images/sphx_glr_making_inset_images_001.png :alt: making inset images :srcset: /auto_examples/Markers/images/sphx_glr_making_inset_images_001.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/Markers/images/sphx_glr_making_inset_images_002.png :alt: Signal :srcset: /auto_examples/Markers/images/sphx_glr_making_inset_images_002.png :class: sphx-glr-multi-img .. GENERATED FROM PYTHON SOURCE LINES 49-54 Dynamic Inset Markers ##################### This example shows how to draw dynamic inset markers, whose position depends on the navigation coordinates .. GENERATED FROM PYTHON SOURCE LINES 55-91 .. code-block:: Python s = hs.signals.Signal2D(np.random.rand(100, 100, 10, 10)) signal2 = hs.signals.Signal2D(np.random.rand(100, 100, 10, 10)) signal2_shape = signal2.axes_manager._signal_shape_in_array def to_ragged(s): return s ragged_signal2 = signal2.map(to_ragged, ragged=True, inplace=False) y = np.linspace( -0.1, 0.1, signal2_shape[0] + 1 ) # making a mesh grid 20% of the size of the main image x = np.linspace( -0.1, 0.1, signal2_shape[1] + 1 ) # making a mesh grid 20% of the size of the main image xx, yy = np.meshgrid(x, y) coords = np.stack([xx, yy], axis=-1) quad = hs.plot.markers.Markers( collection=matplotlib.collections.QuadMesh, coordinates=coords, array=ragged_signal2.data, cmap="hsv", transform="axes", offset_transform="axes", offsets=[[0.7, 0.7]], alpha=1, ) # Put in top right corner s.plot() s.add_marker(quad) .. rst-class:: sphx-glr-horizontal * .. image-sg:: /auto_examples/Markers/images/sphx_glr_making_inset_images_003.png :alt: making inset images :srcset: /auto_examples/Markers/images/sphx_glr_making_inset_images_003.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/Markers/images/sphx_glr_making_inset_images_004.png :alt: Signal :srcset: /auto_examples/Markers/images/sphx_glr_making_inset_images_004.png :class: sphx-glr-multi-img .. rst-class:: sphx-glr-script-out .. code-block:: none [ ] | 0% Completed | 112.77 us [########################################] | 100% Completed | 100.39 ms .. GENERATED FROM PYTHON SOURCE LINES 92-97 Transparent Overlay ################### This example shows how to draw overlay a dynamic image over the signal, whose position depends on the navigation coordinates .. GENERATED FROM PYTHON SOURCE LINES 98-125 .. code-block:: Python s = hs.signals.Signal2D(np.random.rand(100, 100, 10, 10)) signal2 = hs.signals.Signal2D(np.random.rand(100, 100, 10, 10)) y = np.linspace( 0, 1, signal2_shape[0] + 1 ) # making a mesh grid 20% of the size of the main image x = np.linspace( 0, 1, signal2_shape[1] + 1 ) # making a mesh grid 20% of the size of the main image xx, yy = np.meshgrid(x, y) coords = np.stack([xx, yy], axis=-1) quad = hs.plot.markers.Markers( collection=matplotlib.collections.QuadMesh, coordinates=coords, array=ragged_signal2.data, cmap="hsv", transform="axes", offset_transform="display", offsets=[[0, 0]], alpha=0.3, ) # Put in top right corner s.plot() s.add_marker(quad) .. rst-class:: sphx-glr-horizontal * .. image-sg:: /auto_examples/Markers/images/sphx_glr_making_inset_images_005.png :alt: making inset images :srcset: /auto_examples/Markers/images/sphx_glr_making_inset_images_005.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/Markers/images/sphx_glr_making_inset_images_006.png :alt: Signal :srcset: /auto_examples/Markers/images/sphx_glr_making_inset_images_006.png :class: sphx-glr-multi-img .. GENERATED FROM PYTHON SOURCE LINES 126-130 Circular ColorBar ################# This example shows how to a circular Color Bar for shows orientation .. GENERATED FROM PYTHON SOURCE LINES 131-159 .. code-block:: Python n = 360 # the number of secants for the mesh t = np.linspace(0, 2 * np.pi, n) # theta values r = np.linspace(0.6, 1, 2) # radius values change 0.6 to 0 for full circle y = np.sin(t[:, np.newaxis]) * r[np.newaxis, :] / 10 x = np.cos(t[:, np.newaxis]) * r[np.newaxis, :] / 10 coords = np.stack([x, y], axis=-1) quad = hs.plot.markers.Markers( collection=matplotlib.collections.QuadMesh, coordinates=coords, array=t[1:], cmap="hsv", transform="axes", offset_transform="axes", offsets=[[0.75, 0.8]], alpha=1, ) im = np.random.randint(1, 360, (100, 100)) nav = hs.signals.Signal2D(im).T s.plot(navigator=nav, navigator_kwds=dict(cmap="hsv", colorbar=False)) s.add_marker(quad, plot_on_signal=False) .. rst-class:: sphx-glr-horizontal * .. image-sg:: /auto_examples/Markers/images/sphx_glr_making_inset_images_007.png :alt: making inset images :srcset: /auto_examples/Markers/images/sphx_glr_making_inset_images_007.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/Markers/images/sphx_glr_making_inset_images_008.png :alt: Signal :srcset: /auto_examples/Markers/images/sphx_glr_making_inset_images_008.png :class: sphx-glr-multi-img .. GENERATED FROM PYTHON SOURCE LINES 160-161 sphinx_gallery_thumbnail_number = 2 .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 3.724 seconds) .. _sphx_glr_download_auto_examples_Markers_making_inset_images.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: making_inset_images.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: making_inset_images.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: making_inset_images.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_