momepy.subgraph(graph, radius=5, distance=None, meshedness=True, cds_length=True, mode='sum', degree='degree', length='mm_len', mean_node_degree=True, proportion={0: True, 3: True, 4: True}, cyclomatic=True, edge_node_ratio=True, gamma=True, local_closeness=True, closeness_weight=None, verbose=True)[source]#

Calculates all subgraph-based characters. Generating subgraph might be a time consuming activity. If we want to use the same subgraph for more characters, subgraph allows this by generating subgraph and then analysing it using selected options.


A Graph representing a street network. Ideally generated from GeoDataFrame using momepy.gdf_to_nx().

radius: int

Include all neighbors of distance <= radius from n.

distancestr, optional

Use specified edge data key as distance. For example, setting distance=’weight’ will use the edge weight to measure the distance from the node n.

meshednessbool, default True

Calculate meshedness (True or ``False).

cds_lengthbool, default True

Calculate cul-de-sac length (True or ``False).

modestr (defualt ‘sum’)

If 'sum', calculate total cds_length, if 'mean' calculate mean cds_length.


The name of attribute of node degree (momepy.node_degree()).

lengthstr, default mm_len

The name of the attribute of segment length (geographical).

mean_node_degreebool, default True

Calculate mean node degree (True or ``False).

proportiondict, default {3: True, 4: True, 0: True}

Calculate proportion {3: True/False, 4: True/False, 0: True/False}.

cyclomaticbool, default True

Calculate cyclomatic complexity (True or ``False).

edge_node_ratiobool, default True

Calculate edge node ratio (True or ``False).

gammabool, default True

Calculate gamma index (True or ``False).

local_closenessbool, default True

Calculate local closeness centrality (True or ``False).

closeness_weightstr, optional

Use the specified edge attribute as the edge distance in shortest path calculations in closeness centrality algorithm.

verbosebool (default True)

If True, shows progress bars in loops and indication of steps.


A networkx.Graph object.


>>> network_graph = mm.subgraph(network_graph)