.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/lines_bars_and_markers/markevery_demo.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. meta:: :keywords: codex .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_gallery_lines_bars_and_markers_markevery_demo.py: ============== Markevery Demo ============== The ``markevery`` property of `.Line2D` allows drawing markers at a subset of data points. The list of possible parameters is specified at `.Line2D.set_markevery`. In short: - A single integer N draws every N-th marker. - A tuple of integers (start, N) draws every N-th marker, starting at data index *start*. - A list of integers draws the markers at the specified indices. - A slice draws the markers at the sliced indices. - A float specifies the distance between markers as a fraction of the Axes diagonal in screen space. This will lead to a visually uniform distribution of the points along the line, irrespective of scales and zooming. .. GENERATED FROM PYTHON SOURCE LINES 21-43 .. code-block:: default import numpy as np import matplotlib.pyplot as plt # define a list of markevery cases to plot cases = [ None, 8, (30, 8), [16, 24, 32], [0, -1], slice(100, 200, 3), 0.1, 0.4, (0.2, 0.4) ] # data points delta = 0.11 x = np.linspace(0, 10 - 2 * delta, 200) + delta y = np.sin(x) + 1.0 + delta .. GENERATED FROM PYTHON SOURCE LINES 44-46 markevery with linear scales ---------------------------- .. GENERATED FROM PYTHON SOURCE LINES 46-52 .. code-block:: default fig, axs = plt.subplots(3, 3, figsize=(10, 6), constrained_layout=True) for ax, markevery in zip(axs.flat, cases): ax.set_title(f'markevery={markevery}') ax.plot(x, y, 'o', ls='-', ms=4, markevery=markevery) .. image-sg:: /gallery/lines_bars_and_markers/images/sphx_glr_markevery_demo_001.png :alt: markevery=None, markevery=8, markevery=(30, 8), markevery=[16, 24, 32], markevery=[0, -1], markevery=slice(100, 200, 3), markevery=0.1, markevery=0.4, markevery=(0.2, 0.4) :srcset: /gallery/lines_bars_and_markers/images/sphx_glr_markevery_demo_001.png, /gallery/lines_bars_and_markers/images/sphx_glr_markevery_demo_001_2_0x.png 2.0x :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 53-60 markevery with log scales ------------------------- Note that the log scale causes a visual asymmetry in the marker distance for when subsampling the data using an integer. In contrast, subsampling on fraction of figure size creates even distributions, because it's based on fractions of the Axes diagonal, not on data coordinates or data indices. .. GENERATED FROM PYTHON SOURCE LINES 60-68 .. code-block:: default fig, axs = plt.subplots(3, 3, figsize=(10, 6), constrained_layout=True) for ax, markevery in zip(axs.flat, cases): ax.set_title(f'markevery={markevery}') ax.set_xscale('log') ax.set_yscale('log') ax.plot(x, y, 'o', ls='-', ms=4, markevery=markevery) .. image-sg:: /gallery/lines_bars_and_markers/images/sphx_glr_markevery_demo_002.png :alt: markevery=None, markevery=8, markevery=(30, 8), markevery=[16, 24, 32], markevery=[0, -1], markevery=slice(100, 200, 3), markevery=0.1, markevery=0.4, markevery=(0.2, 0.4) :srcset: /gallery/lines_bars_and_markers/images/sphx_glr_markevery_demo_002.png, /gallery/lines_bars_and_markers/images/sphx_glr_markevery_demo_002_2_0x.png 2.0x :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 69-77 markevery on zoomed plots ------------------------- Integer-based *markevery* specifications select points from the underlying data and are independent on the view. In contrast, float-based specifications are related to the Axes diagonal. While zooming does not change the Axes diagonal, it changes the displayed data range, and more points will be displayed when zooming. .. GENERATED FROM PYTHON SOURCE LINES 77-85 .. code-block:: default fig, axs = plt.subplots(3, 3, figsize=(10, 6), constrained_layout=True) for ax, markevery in zip(axs.flat, cases): ax.set_title(f'markevery={markevery}') ax.plot(x, y, 'o', ls='-', ms=4, markevery=markevery) ax.set_xlim((6, 6.7)) ax.set_ylim((1.1, 1.7)) .. image-sg:: /gallery/lines_bars_and_markers/images/sphx_glr_markevery_demo_003.png :alt: markevery=None, markevery=8, markevery=(30, 8), markevery=[16, 24, 32], markevery=[0, -1], markevery=slice(100, 200, 3), markevery=0.1, markevery=0.4, markevery=(0.2, 0.4) :srcset: /gallery/lines_bars_and_markers/images/sphx_glr_markevery_demo_003.png, /gallery/lines_bars_and_markers/images/sphx_glr_markevery_demo_003_2_0x.png 2.0x :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 86-88 markevery on polar plots ------------------------ .. GENERATED FROM PYTHON SOURCE LINES 88-99 .. code-block:: default r = np.linspace(0, 3.0, 200) theta = 2 * np.pi * r fig, axs = plt.subplots(3, 3, figsize=(10, 6), constrained_layout=True, subplot_kw={'projection': 'polar'}) for ax, markevery in zip(axs.flat, cases): ax.set_title(f'markevery={markevery}') ax.plot(theta, r, 'o', ls='-', ms=4, markevery=markevery) plt.show() .. image-sg:: /gallery/lines_bars_and_markers/images/sphx_glr_markevery_demo_004.png :alt: markevery=None, markevery=8, markevery=(30, 8), markevery=[16, 24, 32], markevery=[0, -1], markevery=slice(100, 200, 3), markevery=0.1, markevery=0.4, markevery=(0.2, 0.4) :srcset: /gallery/lines_bars_and_markers/images/sphx_glr_markevery_demo_004.png, /gallery/lines_bars_and_markers/images/sphx_glr_markevery_demo_004_2_0x.png 2.0x :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 10.927 seconds) .. _sphx_glr_download_gallery_lines_bars_and_markers_markevery_demo.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: markevery_demo.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: markevery_demo.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_