.plot()命令不显示任何内容 [英] .plot() command does not display anything

查看:296
本文介绍了.plot()命令不显示任何内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有基于这个问题的代码,只是一个不同的地方使用OSMnx提取受约束的多边形

I have this code based on this question, just a different point Extract constrained polygon using OSMnx

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

I am trying to plot the block in which the point is located but it does nothing, it just prints "Done" but I cannot see any image

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代码

I do not think this may help but I am using Visual Studio Code

非常感谢您

推荐答案

由于我的评论回答了您的问题,因此我在这里为其他人总结一下:

Since my comment answered your question, I will summarize it here for other people:

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

When using plotting library dependent on matplotlib, like geopandas or seaborn, you will need to import matplotlib in order to show the plot. The way matplotlib is imported will depend on whether you are using Jupyter or simple scripting (.py) files.

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

For Jupyter you need to import it like this:

%matplotlib inline

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

For simple scripting (.py) file you need to import it like this:

import matplotlib.pyplot as plt

然后,当您想显示自己的情节时,您只需完成

Then when you want to show your plot you simply do

plt.show()

希望有帮助!

这篇关于.plot()命令不显示任何内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆