1

我按照此处的示例运行了以下代码:

http://matplotlib.org/faq/howto_faq.html#test-whether-a-point-is-inside-a-polygon

非常感谢您的帮助。谢谢你。

>>>import numpy as np
>>>import matplotlib.nxutils as nx
>>>verts = np.array([ [0,0], [0, 1], [1, 1], [1,0]], float)
>>>nx.pnpoly(0.5, 0.5, verts)

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "C:\Python27\lib\site-packages\matplotlib\nxutils.py", line 26, in pnpoly
    return p.contains_point(x, y)
  File "C:\Python27\lib\site-packages\matplotlib\path.py", line 289, in contains_point
    transform = transform.frozen()
AttributeError: 'float' object has no attribute 'frozen'

>>>nx.pnpoly(0.5, 1.5, verts)

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "C:\Python27\lib\site-packages\matplotlib\nxutils.py", line 26, in pnpoly
    return p.contains_point(x, y)
  File "C:\Python27\lib\site-packages\matplotlib\path.py", line 289, in contains_point
    transform = transform.frozen()
AttributeError: 'float' object has no attribute 'frozen'
4

2 回答 2

2

matplotlib 论坛上的用户提供了以下内容,正如我测试的那样:

from matplotlib.path import Path
path = Path(polygonVerts)
isInside = path.contains_point(point)
于 2013-05-14T20:35:22.740 回答
2

虽然pnpoly已被弃用,但您的错误是由一个错误引起的,该错误已在 GitHub 上的此提交中修复。

该错误是由于使用错误的方法签名pnpoly进行代理。contains_point

于 2013-05-19T19:52:12.840 回答