osmnx - plot_route_folium 无向图导致 IndexError: index 0 is out of bounds for axis 0 with size 0 when
问题描述
plot_route_folium 不适用于无向图,我该怎么办?
它以这种方式适用于 Graph
G = ox.graph_from_place(place, simplify=False, custom_filter=custom_filter_ways)
orig = 25635046.0
dest = 3603422387.0
route = nx.shortest_path(G, orig, dest, weight='length')
route_map = ox.plot_route_folium(G, route)
但如果我想做
Gu = ox.get_undirected(G)
route_undirected = nx.shortest_path(Gu, orig, dest, weight='length')
route_map_u = ox.plot_route_folium(Gu, route_undirected)
我收到以下错误:
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
<ipython-input-50-8b91fb9c57b4> in <module>
----> 1 route_map_u = ox.plot_route_folium(Gu, route_undirected)
C:\ProgramData\Anaconda3\envs\ox\lib\site-packages\osmnx\folium.py in plot_route_folium(G, route, route_map, popup_attribute, tiles, zoom, fit_bounds, route_color, route_width, route_opacity, **kwargs)
202 gdf_edges = utils_graph.graph_to_gdfs(G.subgraph(route), nodes=False, fill_edge_geometry=True)
203 route_nodes = list(zip(route[:-1], route[1:]))
--> 204 index = [
205 gdf_edges[(gdf_edges["u"] == u) & (gdf_edges["v"] == v)].index[0] for u, v in route_nodes
206 ]
C:\ProgramData\Anaconda3\envs\ox\lib\site-packages\osmnx\folium.py in <listcomp>(.0)
203 route_nodes = list(zip(route[:-1], route[1:]))
204 index = [
--> 205 gdf_edges[(gdf_edges["u"] == u) & (gdf_edges["v"] == v)].index[0] for u, v in route_nodes
206 ]
207 gdf_route_edges = gdf_edges.loc[index]
C:\ProgramData\Anaconda3\envs\ox\lib\site-packages\pandas\core\indexes\base.py in __getitem__(self, key)
4099 if is_scalar(key):
4100 key = com.cast_scalar_indexer(key, warn_float=True)
-> 4101 return getitem(key)
4102
4103 if isinstance(key, slice):
IndexError: index 0 is out of bounds for axis 0 with size 0
绘图工作就像
fig, ax = ox.plot_graph_route(Gu, route_undirected)
解决方案
请参阅文档:您正在使用的函数需要一个MultiDiGraph
参数,但您正在传递它 a MultiGraph
。尽管该函数不强制执行严格的类型检查,但您已经向它传递了一个意外的参数类型。
推荐阅读
- python - 如何在python中以这种格式“Sun,2019年9月22日09:18:13 GMT”获取当前GMT时间
- c - 如何使用 malloc 从函数返回 char 数组
- google-cloud-platform - 从 Node.js 云函数创建 Kubernetes 作业
- c++ - 在 C++ 中添加日期,使用类
- javascript - 如何逐行打印Vue对象
- python - 基于颜色比较找到两个区域之间的匹配
- selenium - Selenium & Scrapy:最后一个 URL 覆盖其他 URL
- wordpress - 为什么我需要在 docker-compose.yml 中显式声明 env_file?
- typescript - 如何在 Typescript 中扩展模块
- security - 高峰期网站的性能很差