.. 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 .. 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 ============== This example demonstrates the various options for showing a marker at a subset of data points using the ``markevery`` property of a Line2D object. Integer arguments are fairly intuitive. e.g. ``markevery=5`` will plot every 5th marker starting from the first data point. Float arguments allow markers to be spaced at approximately equal distances along the line. The theoretical distance along the line between markers is determined by multiplying the display-coordinate distance of the axes bounding-box diagonal by the value of ``markevery``. The data points closest to the theoretical distances will be shown. A slice or list/array can also be used with ``markevery`` to specify the markers to show. .. GENERATED FROM PYTHON SOURCE LINES 21-53 .. 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, 30], [0, -1], slice(100, 200, 3), 0.1, 0.3, 1.5, (0.0, 0.1), (0.45, 0.1)] # define the figure size and grid layout properties figsize = (10, 8) cols = 3 rows = len(cases) // cols + 1 # define the data for cartesian plots delta = 0.11 x = np.linspace(0, 10 - 2 * delta, 200) + delta y = np.sin(x) + 1.0 + delta def trim_axs(axs, N): """ Reduce *axs* to *N* Axes. All further Axes are removed from the figure. """ axs = axs.flat for ax in axs[N:]: ax.remove() return axs[:N] .. GENERATED FROM PYTHON SOURCE LINES 54-55 Plot each markevery case for linear x and y scales .. GENERATED FROM PYTHON SOURCE LINES 55-62 .. code-block:: default axs = plt.figure(figsize=figsize, constrained_layout=True).subplots(rows, cols) axs = trim_axs(axs, len(cases)) for ax, case in zip(axs, cases): ax.set_title('markevery=%s' % str(case)) ax.plot(x, y, 'o', ls='-', ms=4, markevery=case) .. image:: /gallery/lines_bars_and_markers/images/sphx_glr_markevery_demo_001.png :alt: markevery=None, markevery=8, markevery=(30, 8), markevery=[16, 24, 30], markevery=[0, -1], markevery=slice(100, 200, 3), markevery=0.1, markevery=0.3, markevery=1.5, markevery=(0.0, 0.1), markevery=(0.45, 0.1) :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 63-64 Plot each markevery case for log x and y scales .. GENERATED FROM PYTHON SOURCE LINES 64-73 .. code-block:: default axs = plt.figure(figsize=figsize, constrained_layout=True).subplots(rows, cols) axs = trim_axs(axs, len(cases)) for ax, case in zip(axs, cases): ax.set_title('markevery=%s' % str(case)) ax.set_xscale('log') ax.set_yscale('log') ax.plot(x, y, 'o', ls='-', ms=4, markevery=case) .. image:: /gallery/lines_bars_and_markers/images/sphx_glr_markevery_demo_002.png :alt: markevery=None, markevery=8, markevery=(30, 8), markevery=[16, 24, 30], markevery=[0, -1], markevery=slice(100, 200, 3), markevery=0.1, markevery=0.3, markevery=1.5, markevery=(0.0, 0.1), markevery=(0.45, 0.1) :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 74-78 Plot each markevery case for linear x and y scales but zoomed in note the behaviour when zoomed in. When a start marker offset is specified it is always interpreted with respect to the first data point which might be different to the first visible data point. .. GENERATED FROM PYTHON SOURCE LINES 78-91 .. code-block:: default axs = plt.figure(figsize=figsize, constrained_layout=True).subplots(rows, cols) axs = trim_axs(axs, len(cases)) for ax, case in zip(axs, cases): ax.set_title('markevery=%s' % str(case)) ax.plot(x, y, 'o', ls='-', ms=4, markevery=case) ax.set_xlim((6, 6.7)) ax.set_ylim((1.1, 1.7)) # define data for polar plots r = np.linspace(0, 3.0, 200) theta = 2 * np.pi * r .. image:: /gallery/lines_bars_and_markers/images/sphx_glr_markevery_demo_003.png :alt: markevery=None, markevery=8, markevery=(30, 8), markevery=[16, 24, 30], markevery=[0, -1], markevery=slice(100, 200, 3), markevery=0.1, markevery=0.3, markevery=1.5, markevery=(0.0, 0.1), markevery=(0.45, 0.1) :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 92-93 Plot each markevery case for polar plots .. GENERATED FROM PYTHON SOURCE LINES 93-102 .. code-block:: default axs = plt.figure(figsize=figsize, constrained_layout=True).subplots( rows, cols, subplot_kw={'projection': 'polar'}) axs = trim_axs(axs, len(cases)) for ax, case in zip(axs, cases): ax.set_title('markevery=%s' % str(case)) ax.plot(theta, r, 'o', ls='-', ms=4, markevery=case) plt.show() .. image:: /gallery/lines_bars_and_markers/images/sphx_glr_markevery_demo_004.png :alt: markevery=None, markevery=8, markevery=(30, 8), markevery=[16, 24, 30], markevery=[0, -1], markevery=slice(100, 200, 3), markevery=0.1, markevery=0.3, markevery=1.5, markevery=(0.0, 0.1), markevery=(0.45, 0.1) :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 8.395 seconds) .. _sphx_glr_download_gallery_lines_bars_and_markers_markevery_demo.py: .. only :: html .. container:: sphx-glr-footer :class: 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 Keywords: matplotlib code example, codex, python plot, pyplot `Gallery generated by Sphinx-Gallery `_