In [1]:
import networkx as nx
import osmnx as ox
% matplotlib inline
In [2]:
# INPUT
# Path to SR drive_service network
path = "data/steyr_driveService.graphml"
# Load graph
G = nx.read_graphml(path)
print nx.info(G)
In [4]:
# Centrality Measures
# Beweenness Centrality
betw_cent = nx.betweenness_centrality(G)
node_btw_max, betw_max = ("", 0)
for k,v in betw_cent.iteritems():
if v > betw_max:
node_btw_max = k
betw_max = v
else:
pass
print "\nBetweenness Centrality"
print node_btw_max + ": " + str(betw_max)
# Closeness Centrality
close_cent = nx.closeness_centrality(G)
node_cl_max, close_max = ("", 0)
for k,v in close_cent.iteritems():
if v > close_max:
node_cl_max = k
close_max = v
else:
pass
print "\nCloseness Centrality"
print node_cl_max + ": " + str(close_max)
In [5]:
# Plot Centrality Measures on map
north, south, east, west = 48.0746, 48.0247, 14.4698, 14.3758
G_map = ox.graph_from_bbox(north, south, east, west, network_type="drive_service")
G_map = ox.project_graph(G_map)
node_size = [50 if str(node) == node_btw_max else (50 if str(node) == node_cl_max else 5)
for node in G_map.nodes()]
node_color = ["r" if str(node) == node_btw_max else ("b" if str(node) == node_cl_max else "#33d5bb")
for node in G_map.nodes()]
fig, ax = ox.plot_graph(G_map, node_size=node_size, node_color=node_color)
In [ ]:
In [ ]: