
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "gallery/misc/bbox_intersect.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_misc_bbox_intersect.py>`
        to download the full example code.

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

.. _sphx_glr_gallery_misc_bbox_intersect.py:


==================================
Identify whether artists intersect
==================================

The lines intersecting the rectangle are colored in red, while the others
are left as blue lines. This example showcases the `.intersects_bbox` function.

.. GENERATED FROM PYTHON SOURCE LINES 10-40



.. image-sg:: /gallery/misc/images/sphx_glr_bbox_intersect_001.png
   :alt: bbox intersect
   :srcset: /gallery/misc/images/sphx_glr_bbox_intersect_001.png, /gallery/misc/images/sphx_glr_bbox_intersect_001_2_00x.png 2.00x
   :class: sphx-glr-single-img





.. code-block:: Python


    import matplotlib.pyplot as plt
    import numpy as np

    from matplotlib.path import Path
    from matplotlib.transforms import Bbox

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


    left, bottom, width, height = (-1, -1, 2, 2)
    rect = plt.Rectangle((left, bottom), width, height,
                         facecolor="black", alpha=0.1)

    fig, ax = plt.subplots()
    ax.add_patch(rect)

    bbox = Bbox.from_bounds(left, bottom, width, height)

    for i in range(12):
        vertices = (np.random.random((2, 2)) - 0.5) * 6.0
        path = Path(vertices)
        if path.intersects_bbox(bbox):
            color = 'r'
        else:
            color = 'b'
        ax.plot(vertices[:, 0], vertices[:, 1], color=color)

    plt.show()


.. _sphx_glr_download_gallery_misc_bbox_intersect.py:

.. only:: html

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

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

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

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

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

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

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


.. only:: html

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

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