OSMNX:如何绘制一个国家边界的铁路网络图

2024-06-16 08:35:16 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用Python上的OSMNX将比利时的国家边界与铁路网络合并。以了解列车路线的运行位置(并突出显示其中一些路线)。我尝试了以下方法,但没有达到预期效果:

import matplotlib.pyplot as plt
import networkx as nx
import osmnx as ox
ox.config(use_cache=True, log_console=True)

place = 'Belgium'

#import the needed railway network
B_osmnx = ox.graph_from_place(place,
                        retain_all=False, truncate_by_edge=True, simplify=True,
 
                              custom_filter='["railway"~"rail"]')
#import the country borders
Belgium = ox.geocode_to_gdf('Belgium')
Belgium = ox.project_gdf(Belgium)

#create the railway network graph
fig, ax = ox.plot_graph(B_osmnx, node_size=0.5 , edge_color='r', show=False, close=False)

#add the borders
Belgium.plot(ax=ax, color='w')

plt.show()

Output code

最后,我想使用ox.plot_graph_routes()函数而不是ox.graph_from_place()。这样我可以突出几个路线

你有解决办法吗?谢谢


Tags: theimportfalsetrueplotasplaceplt