.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/geometry/simplification/plot_01_douglas_peucker.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_api_gallery_geometry_simplification_plot_01_douglas_peucker.py: Douglas-Peucker line simplification ========================================= Simplifies a wiggly coastline-like curve at several tolerances. Larger tolerances keep fewer vertices, and every discarded vertex stays within the tolerance of the simplified line. .. GENERATED FROM PYTHON SOURCE LINES 11-16 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from mathematicskit.geometry import douglas_peucker .. GENERATED FROM PYTHON SOURCE LINES 17-19 A rough curve and its simplifications ----------------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 19-32 .. code-block:: Python rng = np.random.default_rng(2) x = np.linspace(0, 10, 2000) y = np.sin(x) + 0.3 * np.sin(5 * x) + 0.05 * np.cumsum(rng.normal(size=x.size)) / np.sqrt(x.size) * 10 line = np.column_stack([x, y]) fig, ax = plt.subplots(figsize=(9, 4)) ax.plot(*line.T, color="0.7", lw=3, label=f"original ({len(line)} points)") for eps, color in ((0.05, "tab:blue"), (0.2, "tab:green"), (0.6, "tab:red")): simple = douglas_peucker(line, eps) ax.plot(*simple.T, "o-", color=color, ms=3, lw=1, label=f"epsilon = {eps}: {len(simple)} points") ax.legend() ax.set_title("Douglas-Peucker (1973)") .. image-sg:: /api/gallery/geometry/simplification/images/sphx_glr_plot_01_douglas_peucker_001.png :alt: Douglas-Peucker (1973) :srcset: /api/gallery/geometry/simplification/images/sphx_glr_plot_01_douglas_peucker_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none Text(0.5, 1.0, 'Douglas-Peucker (1973)') .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.035 seconds) .. _sphx_glr_download_api_gallery_geometry_simplification_plot_01_douglas_peucker.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_01_douglas_peucker.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_01_douglas_peucker.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_01_douglas_peucker.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_