Get startedGet started for free

Circos plot

Finally, you're going to make a Circos plot of the network!

This exercise is part of the course

Introduction to Network Analysis in Python

View Course

Exercise instructions

  • Make a Circos plot of the network, again, with GitHub users sorted by their degree, and grouped and colored by their 'grouping' key. 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.
    • Create the circos plot c by specifying three parameters in addition to the graph G: the sort_by argument, which is 'degree', and the group_by and node_color_by arguments, which are both 'grouping'.
    • Draw the Circos plot to the screen.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Import necessary modules
from nxviz import circos
import matplotlib.pyplot as plt

# Iterate over all the nodes, including the metadata
for n, d in ____:

    # Calculate the degree of each node: G.node[n]['degree']
    ____ = ____

# Create the Circos plot: c
c = ____

# Draw the Circos plot to the screen
____
plt.show()
Edit and Run Code