如何绘制 Shapely 点列表

Hel*_*rts 7 python list point matplotlib shapely

Point我根据点数据集创建了 Shapely 对象的列表。我如何绘制下面的点列表?

points = [Point(-4.85624511894443, 37.1837967179202), 
          Point(-4.855703975302475, 37.18401757756585),
          Point(-4.85516283166052, 37.1842384372115),
          Point(-4.85343407576431, 37.182006629169),
          Point(-4.85347524651836, 37.1804461589773),
          Point(-4.855792124429867, 37.18108913443582),
          Point(-4.85624511894443, 37.1837967179202)]
Run Code Online (Sandbox Code Playgroud)

Geo*_*rgy 11

您可以通过访问和的属性来获取xy坐标的两个列表,然后使用例如Matplotlib 的或函数,如下所示:xyPointplt.scatterplt.plot

import matplotlib.pyplot as plt
from shapely.geometry import Point

points = [Point(-4.85624511894443, 37.1837967179202), 
          Point(-4.855703975302475, 37.18401757756585),
          Point(-4.85516283166052, 37.1842384372115),
          Point(-4.85343407576431, 37.182006629169),
          Point(-4.85347524651836, 37.1804461589773),
          Point(-4.855792124429867, 37.18108913443582),
          Point(-4.85624511894443, 37.1837967179202)]
xs = [point.x for point in points]
ys = [point.y for point in points]
plt.scatter(xs, ys)
# or plt.plot(xs, ys) if you want to connect points by lines
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述


如果您使用 Jupyter Notebook 或 Jupyter Lab,您可以将点列表包装在对象中MultiPoint以获取 SVG 图像。当您想要快速绘制某些内容而不导入 Matpotlib 时,这对于调试目的非常有用。

>>> MultiPoint(points)
Run Code Online (Sandbox Code Playgroud)

给出:
在此输入图像描述