
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "gallery/lines_bars_and_markers/eventcollection_demo.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

    .. meta::
        :keywords: codex

    .. note::
        :class: sphx-glr-download-link-note

        :ref:`Go to the end <sphx_glr_download_gallery_lines_bars_and_markers_eventcollection_demo.py>`
        to download the full example code.

.. rst-class:: sphx-glr-example-title

.. _sphx_glr_gallery_lines_bars_and_markers_eventcollection_demo.py:


====================
EventCollection Demo
====================

Plot two curves, then use `.EventCollection`\s to mark the locations of the x
and y data points on the respective Axes for each curve.

.. GENERATED FROM PYTHON SOURCE LINES 9-64

.. code-block:: Python


    import matplotlib.pyplot as plt
    import numpy as np

    from matplotlib.collections import EventCollection

    # Fixing random state for reproducibility
    np.random.seed(19680801)

    # create random data
    xdata = np.random.random([2, 10])

    # split the data into two parts
    xdata1 = xdata[0, :]
    xdata2 = xdata[1, :]

    # sort the data so it makes clean curves
    xdata1.sort()
    xdata2.sort()

    # create some y data points
    ydata1 = xdata1 ** 2
    ydata2 = 1 - xdata2 ** 3

    # plot the data
    fig = plt.figure()
    ax = fig.add_subplot(1, 1, 1)
    ax.plot(xdata1, ydata1, color='tab:blue')
    ax.plot(xdata2, ydata2, color='tab:orange')

    # create the events marking the x data points
    xevents1 = EventCollection(xdata1, color='tab:blue', linelength=0.05)
    xevents2 = EventCollection(xdata2, color='tab:orange', linelength=0.05)

    # create the events marking the y data points
    yevents1 = EventCollection(ydata1, color='tab:blue', linelength=0.05,
                               orientation='vertical')
    yevents2 = EventCollection(ydata2, color='tab:orange', linelength=0.05,
                               orientation='vertical')

    # add the events to the axis
    ax.add_collection(xevents1)
    ax.add_collection(xevents2)
    ax.add_collection(yevents1)
    ax.add_collection(yevents2)

    # set the limits
    ax.set_xlim([0, 1])
    ax.set_ylim([0, 1])

    ax.set_title('line plot with data points')

    # display the plot
    plt.show()




.. image-sg:: /gallery/lines_bars_and_markers/images/sphx_glr_eventcollection_demo_001.png
   :alt: line plot with data points
   :srcset: /gallery/lines_bars_and_markers/images/sphx_glr_eventcollection_demo_001.png, /gallery/lines_bars_and_markers/images/sphx_glr_eventcollection_demo_001_2_00x.png 2.00x
   :class: sphx-glr-single-img





.. GENERATED FROM PYTHON SOURCE LINES 65-69

.. tags::

   plot-type: eventplot
   level: intermediate


.. _sphx_glr_download_gallery_lines_bars_and_markers_eventcollection_demo.py:

.. only:: html

  .. container:: sphx-glr-footer sphx-glr-footer-example

    .. container:: sphx-glr-download sphx-glr-download-jupyter

      :download:`Download Jupyter notebook: eventcollection_demo.ipynb <eventcollection_demo.ipynb>`

    .. container:: sphx-glr-download sphx-glr-download-python

      :download:`Download Python source code: eventcollection_demo.py <eventcollection_demo.py>`

    .. container:: sphx-glr-download sphx-glr-download-zip

      :download:`Download zipped: eventcollection_demo.zip <eventcollection_demo.zip>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_
