Skip to content

Instantly share code, notes, and snippets.

@MJacobs1985
Created September 29, 2021 08:09
Show Gist options
  • Save MJacobs1985/f404e339afbe4d0f29ee36888166b928 to your computer and use it in GitHub Desktop.
Save MJacobs1985/f404e339afbe4d0f29ee36888166b928 to your computer and use it in GitHub Desktop.
Network Graphs for Epidemiology
G = nx.Graph()
G.add_edge(1, 7)
e = (2, 3)
G.add_edge(*e)
nx.draw(G, with_labels=True, font_weight='bold', font_color='white', node_color='black', node_size=500, alpha=0.8, edge_color='orange')
G.add_edges_from([(1, 2), (1, 3)])
nx.draw(G, with_labels=True, font_weight='bold', font_color='white', node_color='black', node_size=500, alpha=0.8, edge_color='orange')
H = nx.path_graph(10)
G.add_edges_from(H.edges)
nx.draw(G, with_labels=True, font_weight='bold', font_color='white', node_color='black', node_size=500, alpha=0.8, edge_color='orange')
G = nx.Graph()
G.add_edge(1, 2)
H = nx.DiGraph(G) # create a DiGraph using the connections from G
list(H.edges())
[(1, 2), (2, 1)]
edgelist = [(0, 1), (1, 2), (2, 3)]
H = nx.Graph(edgelist)
nx.draw(H, with_labels=True, font_weight='bold', font_color='white', node_color='black', node_size=500, alpha=0.8, edge_color='orange')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment