.plot() 命令不显示任何内容

.plot() command does not display anything

我有这个基于这个问题的代码,只是不同点

我正在尝试绘制该点所在的块,但它什么也没做,它只打印 "Done" 但我看不到任何图像

import osmnx as ox
import geopandas as gpd
import shapely

point = (50.090464, 14.400070)

streets_graph = ox.graph_from_point(point, distance=500, network_type='drive')
streets_graph = ox.project_graph(streets_graph)

streets = ox.save_load.graph_to_gdfs(streets_graph, nodes=False, edges=True,
                                     node_geometry=False, fill_edge_geometry=True)

point = streets.unary_union.centroid

polygons = shapely.ops.polygonize(streets.geometry)
polygons = gpd.GeoSeries(polygons)

target = polygons.loc[polygons.contains(point)]

target_streets = streets.loc[streets.intersection(target.iloc[0]).type == 'MultiLineString']

ax = target_streets.plot()
gpd.GeoSeries([point]).plot(ax=ax, color='r')

print("Done")

我认为这可能没有帮助,但我正在使用 Visual Studio 代码

非常感谢

既然我的评论回答了你的问题,我在这里总结一下供其他人使用:

当使用依赖于 matplotlib 的绘图库时,如 geopandas 或 seaborn,您需要导入 matplotlib 才能显示绘图。导入 matplotlib 的方式将取决于您使用的是 Jupyter 还是简单的脚本 (.py) 文件。

对于 Jupyter,您需要像这样导入它:

%matplotlib inline

对于简单的脚本 (.py) 文件,您需要像这样导入它:

import matplotlib.pyplot as plt

然后当你想展示你的情节时,你只需做

plt.show()

希望对您有所帮助!