Arc plot
Next up, let's use the Arc plot to visualize the network. You're going to practice sorting the nodes in the graph as well.
Note: this exercise may take about 4-7 seconds to execute if done correctly.
This exercise is part of the course
Introduction to Network Analysis in Python
Exercise instructions
- Make an Arc plot of the GitHub collaboration network, with authors sorted by degree. To do this:
- Iterate over all the nodes in
G, including the metadata (by specifyingdata=True). - In each iteration of the loop, calculate the degree of each node
nwithnx.degree()and set its'degree'attribute.nx.degree()accepts two arguments: A graph and a node. - Create the
arcplotaby specifying two parameters: thegraphargument, which isG, and thesort_byargument, which is'degree', so that the nodes are sorted. - Display the
arcplot to the screen.
- Iterate over all the nodes in
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Import necessary modules
from nxviz import arc
import matplotlib.pyplot as plt
# Iterate over all the nodes in G, including the metadata
for n, d in ____:
# Calculate the degree of each node: G.node[n]['degree']
____ = ____
# Create the Arc plot: a
a = ____
# Draw the Arc plot to the screen
plt.show()