.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/Markers/polygons.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_polygons.py: Polygon Markers ================ .. GENERATED FROM PYTHON SOURCE LINES 8-9 Create a signal .. GENERATED FROM PYTHON SOURCE LINES 9-19 .. code-block:: Python import hyperspy.api as hs import matplotlib.pyplot as plt import numpy as np # Create a Signal2D with 2 navigation dimensions rng = np.random.default_rng(0) data = np.ones((25, 25, 100, 100)) s = hs.signals.Signal2D(data) .. GENERATED FROM PYTHON SOURCE LINES 20-22 This first example shows how to draw static polygon markers using the matplotlib PolygonCollection .. GENERATED FROM PYTHON SOURCE LINES 22-41 .. code-block:: Python # Define the vertexes of the polygons # poylgon1: [[x0, y0], [x1, y1], [x2, y2], [x3, x3]] # poylgon2: [[x0, y0], [x1, y1], [x2, y2]] # ... poylgon1 = [[1, 1], [20, 20], [1, 20], [25, 5]] poylgon2 = [[50, 60], [90, 40], [60, 40], [23, 60]] verts = [poylgon1, poylgon2] m = hs.plot.markers.Polygons( verts=verts, linewidth=3, facecolors=('g',), ) s.plot() s.add_marker(m) .. rst-class:: sphx-glr-horizontal * .. image-sg:: /auto_examples/Markers/images/sphx_glr_polygons_001.png :alt: polygons :srcset: /auto_examples/Markers/images/sphx_glr_polygons_001.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/Markers/images/sphx_glr_polygons_002.png :alt: Signal :srcset: /auto_examples/Markers/images/sphx_glr_polygons_002.png :class: sphx-glr-multi-img .. GENERATED FROM PYTHON SOURCE LINES 42-47 Dynamic Polygon Markers ####################### This example shows how to draw dynamic polygon markers, whose position depends on the navigation coordinates .. GENERATED FROM PYTHON SOURCE LINES 48-65 .. code-block:: Python verts = np.empty(s.axes_manager.navigation_shape, dtype=object) for ind in np.ndindex(verts.shape): verts[ind] = rng.random((10, 4, 2)) * 100 # Get list of colors colors = list(plt.rcParams['axes.prop_cycle'].by_key()['color']) m = hs.plot.markers.Polygons( verts=verts, facecolors=colors, linewidth=3, alpha=0.6 ) s.plot() s.add_marker(m) .. rst-class:: sphx-glr-horizontal * .. image-sg:: /auto_examples/Markers/images/sphx_glr_polygons_003.png :alt: polygons :srcset: /auto_examples/Markers/images/sphx_glr_polygons_003.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/Markers/images/sphx_glr_polygons_004.png :alt: Signal :srcset: /auto_examples/Markers/images/sphx_glr_polygons_004.png :class: sphx-glr-multi-img .. GENERATED FROM PYTHON SOURCE LINES 66-67 sphinx_gallery_thumbnail_number = 2 .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 2.067 seconds) .. _sphx_glr_download_auto_examples_Markers_polygons.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: polygons.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: polygons.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_