{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Markevery Demo\n\nThe ``markevery`` property of `.Line2D` allows drawing markers at a subset of\ndata points.\n\nThe list of possible parameters is specified at `.Line2D.set_markevery`.\nIn short:\n\n- A single integer N draws every N-th marker.\n- A tuple of integers (start, N) draws every N-th marker, starting at data\n  index *start*.\n- A list of integers draws the markers at the specified indices.\n- A slice draws the markers at the sliced indices.\n- A float specifies the distance between markers as a fraction of the Axes\n  diagonal in screen space. This will lead to a visually uniform distribution\n  of the points along the line, irrespective of scales and zooming.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import matplotlib.pyplot as plt\nimport numpy as np\n\n# define a list of markevery cases to plot\ncases = [\n    None,\n    8,\n    (30, 8),\n    [16, 24, 32],\n    [0, -1],\n    slice(100, 200, 3),\n    0.1,\n    0.4,\n    (0.2, 0.4)\n]\n\n# data points\ndelta = 0.11\nx = np.linspace(0, 10 - 2 * delta, 200) + delta\ny = np.sin(x) + 1.0 + delta"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## markevery with linear scales\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "fig, axs = plt.subplots(3, 3, figsize=(10, 6), layout='constrained')\nfor ax, markevery in zip(axs.flat, cases):\n    ax.set_title(f'markevery={markevery}')\n    ax.plot(x, y, 'o', ls='-', ms=4, markevery=markevery)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## markevery with log scales\n\nNote that the log scale causes a visual asymmetry in the marker distance for\nwhen subsampling the data using an integer. In contrast, subsampling on\nfraction of figure size creates even distributions, because it's based on\nfractions of the Axes diagonal, not on data coordinates or data indices.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "fig, axs = plt.subplots(3, 3, figsize=(10, 6), layout='constrained')\nfor ax, markevery in zip(axs.flat, cases):\n    ax.set_title(f'markevery={markevery}')\n    ax.set_xscale('log')\n    ax.set_yscale('log')\n    ax.plot(x, y, 'o', ls='-', ms=4, markevery=markevery)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## markevery on zoomed plots\n\nInteger-based *markevery* specifications select points from the underlying\ndata and are independent on the view. In contrast, float-based specifications\nare related to the Axes diagonal. While zooming does not change the Axes\ndiagonal, it changes the displayed data range, and more points will be\ndisplayed when zooming.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "fig, axs = plt.subplots(3, 3, figsize=(10, 6), layout='constrained')\nfor ax, markevery in zip(axs.flat, cases):\n    ax.set_title(f'markevery={markevery}')\n    ax.plot(x, y, 'o', ls='-', ms=4, markevery=markevery)\n    ax.set_xlim(6, 6.7)\n    ax.set_ylim(1.1, 1.7)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## markevery on polar plots\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "r = np.linspace(0, 3.0, 200)\ntheta = 2 * np.pi * r\n\nfig, axs = plt.subplots(3, 3, figsize=(10, 6), layout='constrained',\n                        subplot_kw={'projection': 'polar'})\nfor ax, markevery in zip(axs.flat, cases):\n    ax.set_title(f'markevery={markevery}')\n    ax.plot(theta, r, 'o', ls='-', ms=4, markevery=markevery)\n\nplt.show()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        ".. tags::\n\n   component: marker\n   plot-type: line\n   level: beginner\n\n"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.14.6"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}