python - matplotlib pnpoly 例子结果报错

标签 python matplotlib attributeerror point-in-polygon

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

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'

最佳答案

matplotlib 论坛上的一位用户提供了以下内容,经我测试可以正常工作:

from matplotlib.path import Path
path = Path(polygonVerts)
isInside = path.contains_point(point)

关于python - matplotlib pnpoly 例子结果报错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16452509/

相关文章:

python - 如何使用 prometheus 客户端从作为 uwsgi 服务器运行的 Django 应用程序导出应用程序指标?

python - 在循环seaborn图中共享次要y轴

python - MatPlotLib如何中英文混合

python - harcascadePath = cv2.data.haarcascades + 'haarcascade_frontalface_default.xml'

python - __getattr__ 在模块上

python - 为什么 PyCharm 不允许在方法命名中使用大写字母?

Python 3 : Finding word which appears the most times without using import or counter or dictionary, 只有简单的工具,如 .split() 和 .lower()

python - 我的 matplotlib 标题被裁剪

python - AttributeError: 'tuple' 对象没有属性 'sort'

python - 有没有更优雅的方法用 Python 编写这个?