Sophie

Sophie

distrib > Fedora > 18 > i386 > by-pkgid > bf21b4394f4d7fa09e3626145d3315e0 > files > 128

python-matplotlib-doc-1.2.0-14.fc18.i686.rpm

.. _api-bbox_intersect:

api example code: bbox_intersect.py
===================================



.. plot:: /builddir/build/BUILD/matplotlib-1.2.0/doc/mpl_examples/api/bbox_intersect.py

::

    import numpy as np
    import matplotlib.pyplot as plt
    from matplotlib.transforms import Bbox
    from matplotlib.path import Path
    
    rect = plt.Rectangle((-1, -1), 2, 2, facecolor="#aaaaaa")
    plt.gca().add_patch(rect)
    bbox = Bbox.from_bounds(-1, -1, 2, 2)
    
    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'
        plt.plot(vertices[:,0], vertices[:,1], color=color)
    
    plt.show()
    

Keywords: python, matplotlib, pylab, example, codex (see :ref:`how-to-search-examples`)