Note

Go to the endto download the full example code.

Identify whether artists intersect#

The lines intersecting the rectangle are colored in red, while the othersare left as blue lines. This example showcases theintersects_bbox function.

bbox intersect
importmatplotlib.pyplotaspltimportnumpyasnpfrommatplotlib.pathimportPathfrommatplotlib.transformsimportBbox# Fixing random state for reproducibilitynp.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)foriinrange(12):vertices=(np.random.random((2,2))-0.5)*6.0path=Path(vertices)ifpath.intersects_bbox(bbox):color='r'else:color='b'ax.plot(vertices[:,0],vertices[:,1],color=color)plt.show()

Gallery generated by Sphinx-Gallery