Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Bug]: Polygon.contains_point() only works if transparency is zero #27026

Open
@adriandelser

Description

@adriandelser

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp