.plot() command does not display anything

大城市里の小女人 提交于 2020-02-25 04:14:07

问题


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")

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

Thank you very much


回答1:


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

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.

For Jupyter you need to import it like this:

%matplotlib inline

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()

Hope it helps!



来源:https://stackoverflow.com/questions/60119176/plot-command-does-not-display-anything

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!