如何绘制形状点列表
How to plot a list of Shapely points
我根据点数据集创建了一个 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)]
通过访问Matplotlib的Point
and then use, for example, plt.scatter
or plt.plot
函数的x
和y
属性,可以得到x
和y
坐标的两个列表,如下所示:
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
如果您使用的是 Jupyter Notebook 或 Jupyter Lab,您可以将点列表包装在 MultiPoint
对象中以获得 SVG 图像。当您想在不导入 Matpotlib 的情况下快速绘制某些内容时,这对于调试目的很有用。
>>> MultiPoint(points)
给出:
我根据点数据集创建了一个 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)]
通过访问Matplotlib的Point
and then use, for example, plt.scatter
or plt.plot
函数的x
和y
属性,可以得到x
和y
坐标的两个列表,如下所示:
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
如果您使用的是 Jupyter Notebook 或 Jupyter Lab,您可以将点列表包装在 MultiPoint
对象中以获得 SVG 图像。当您想在不导入 Matpotlib 的情况下快速绘制某些内容时,这对于调试目的很有用。
>>> MultiPoint(points)
给出: