Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Description
Bug summary
When trying to see if a Polygon contains a point, the contains_point() method only seems to work if alpha is set to 0 or no options are set when defining the polygon. (mpl version = 3.8.0)
Code for reproduction
frommatplotlib.patchesimportPolygonvertices= [[0,0],[0,1],[1,1],[1,0]]# Squarepoint= [0.5,0.5]# Point inside squarepoly0=Polygon(vertices,closed=True,fill=True,color=(1,0,0,1))# Falsepoly1=Polygon(vertices,closed=True,fill=True,color='r')# Falsepoly2=Polygon(vertices,closed=True,fill=True,color=(1,0,0,0))# Truepoly3=Polygon(vertices,fill=False,alpha=0)# Truepoly4=Polygon(vertices,fill=False)# Falsepoly5=Polygon(vertices)# Trueforidx,polyinenumerate((poly0,poly1,poly2,poly3,poly4,poly5)):print(f"Polygon{idx} contains point{point}:{poly.contains_point(point)}")
Actual outcome
Polygon 0 contains point [0.5, 0.5]: False
Polygon 1 contains point [0.5, 0.5]: False
Polygon 2 contains point [0.5, 0.5]: True
Polygon 3 contains point [0.5, 0.5]: True
Polygon 4 contains point [0.5, 0.5]: False
Polygon 5 contains point [0.5, 0.5]: True
Expected outcome
Should return True for all polygons since the point is inside them all.
Additional information
Tested in mpl v3.7.1 and v3.8.0 with identical outcomes
Also fails if fill=False and alpha is not set.
Temporary fix is to set alpha to 0.
Operating system
MacOS 12.5.1 Monterrey
Matplotlib Version
3.8.0
Matplotlib Backend
MacOSX
Python version
Python 3.11.5
Jupyter version
No response
Installation
pip