Drawing network graphs
A network graph shows who is linked to whom. Attach a table of people and a table of links, ask for a graph, and press Run. The graph is drawn on your computer, and you can click a person to see their details and who they are linked to.
Follow along: download gang-nodes.csv (under 1 KB) and gang-edges.csv (under 1 KB) and attach them to a new chat. They are the small gang network that comes with crimepy: 22 people and the links between them.
1. Attach the two tables
Drag both files onto the chat, or press Attach and choose them. One lists the people, one row each; the other lists the links, with the two people each one joins.
Expand2. Ask for a graph
Say which columns to show. Here: "Turn these into a network graph. Color the people by Attended and size them by TotalInc." The assistant writes Python with network_graph, the app's graph drawing.
Expand3. Press Run
The graph appears in the chat, with a legend for the colors and sizes. Drag a person to move them, and scroll to zoom.
Expand4. Look at one person
Click a person, or type a name in Find a node (here "20"). The panel shows their columns and who they are linked to, and everyone else fades. Click a name in the panel to go to that person.
Expand5. Change the layout
Layout sets how the people are placed. Tree starts from the chosen person and puts the people linked to them below, then the people linked to those.
ExpandGood to know
- A notebook works the same way: end a cell with network_graph(...). Find, the details panel, and the layouts are there too.
- network_graph takes a networkx graph as well, so you can size people by a measure from networkx, such as betweenness centrality.
- Save graph under the graph saves it as an HTML file that opens in any browser.
- Exports and Send output to chat include a picture of the graph as it is on screen.