我根据点数据集创建了Shapely 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)]
您可以通过访问x
的y
和x
属性来获得y
和Point
坐标的两个列表,然后使用Matplotlib的Point
或plt.scatter
函数,如下所示:
plt.scatter
[如果使用Jupyter Notebook或Jupyter Lab,则可以将点列表包装在plt.plot
对象中以获得SVG图像。当您想快速绘制某些内容而不导入Matpotlib时,这对于调试目的很有用。
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