.. 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%| | 0/2 [00:00` .. 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 `_