Aan de slagGa gratis aan de slag

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.

Deze oefening maakt deel uit van de cursus

Introduction to Network Analysis in Python

Cursus bekijken

Oefeninstructies

  • 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 specifying data=True).
    • In each iteration of the loop, calculate the degree of each node n with nx.degree() and set its 'degree' attribute. nx.degree() accepts two arguments: A graph and a node.
    • Create the arc plot a by specifying two parameters: the graph argument, which is G, and the sort_by argument, which is 'degree', so that the nodes are sorted.
    • Display the arc plot to the screen.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# 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()
Code bewerken en uitvoeren