如何绘制点和线串列表?

hel*_*pme 3 python geometry geo shapely geopandas

大家好,有没有办法绘制线串列表和点列表

例如我有

line_string = [LINESTRING (-1.15.12 9.9, -1.15.13 9.93), LINESTRING (-2.15.12 8.9, -2.15.13 8.93)]
point = [POINT (5.41 3.9), POINT (6.41 2.9)]
Run Code Online (Sandbox Code Playgroud)

我的目标是拥有一张地图或图表,它可以向我显示点与线串的连接位置。

先感谢您

编辑

当我绘制它的样子时,谢谢大家的悲伤回答。我认为问题在于,有些 LINESTRINGS 有 4 个点(LINESTRING (-1.15.12 9.9, -1.15.13 9.93, -5.15.13 5.53, -3.15.13 2.23)),有些有 3 个点。有没有办法更好地绘制这些?

在此输入图像描述

Mat*_*ish 6

您可以使用 geopandas 脚本层轻松访问 matplotlib。

from shapely.geometry import LineString, Point
import geopandas as gpd    

line_strings = [LineString([(-1.15, 0.12), (9.9, -1.15), (0.13, 9.93)]),
                    LineString([(-2.15, 0.12), (8.9, -2.15), (0.13 , 8.93)])]
points = [Point(5.41, 3.9), Point (6.41, 2.9)]

geom = line_strings + points
gdf = gpd.GeoDataFrame(geometry=geom)

gdf.plot()
Run Code Online (Sandbox Code Playgroud)

根据您的评论进行编辑。如果您想放大某些区域,可以使用 Bokeh 制作交互式绘图。

from bokeh.plotting import figure, show

p = figure(title="interactive plot example", x_axis_label='x', y_axis_label='y')

for ls in line_strings:

    x, y = ls.coords.xy
    p.line(x, y, legend_label="lines", color="blue", line_width=2)
    

for point in points:
    
    p.circle(point.x, point.y, legend_label="points", size=5, color="red", alpha=0.5)
    

show(p)
Run Code Online (Sandbox Code Playgroud)

matplotlib 示例

散景样本