.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/Markers/plot_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_plot_polygons.py: Polygons ======== Draw closed polygons on a 2-D image with :meth:`~anyplotlib.figure_plots.Plot2D.add_polygons`. Use ``markers["polygons"]["name"].set(...)`` to update them live. .. GENERATED FROM PYTHON SOURCE LINES 9-31 .. code-block:: Python import numpy as np import anyplotlib as vw rng = np.random.default_rng(5) data = rng.standard_normal((128, 128)).cumsum(0).cumsum(1) data = (data - data.min()) / (data.max() - data.min()) xy = np.linspace(0, 10, 128) fig, ax = vw.subplots(1, 1, figsize=(460, 460)) v = ax.imshow(data, axes=[xy, xy], units="nm") triangle = [[64.0, 10.0], [100.0, 60.0], [28.0, 60.0]] hexagon = [[64.0 + 28 * np.cos(np.radians(60 * k)), 95.0 + 28 * np.sin(np.radians(60 * k))] for k in range(6)] v.add_polygons([triangle, hexagon], name="shapes", edgecolors="#69f0ae", facecolors="#69f0ae22", linewidths=2.0, label="shapes", labels=["triangle", "hexagon"]) fig .. raw:: html
.. GENERATED FROM PYTHON SOURCE LINES 32-35 Live update ----------- Change the stroke and fill colour of every polygon at once. .. GENERATED FROM PYTHON SOURCE LINES 35-39 .. code-block:: Python v.markers["polygons"]["shapes"].set(edgecolors="#e040fb", facecolors="#e040fb33") fig .. raw:: html
.. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.054 seconds) .. _sphx_glr_download_auto_examples_Markers_plot_polygons.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_polygons.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_polygons.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_polygons.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_