1. Learn
  2. /
  3. Courses
  4. /
  5. Intermediate Network Analysis in Python

Exercise

Plotting using nxviz

Now, you're going to practice creating a CircosPlot using nxviz! As a bonus preview of what's coming up in the next video, there's a little segment on the bipartite keyword in this exercise!

Here, the degree centrality score of each node has been added to their metadata dictionary for you using the following code:

# Add the degree centrality score of each node to their metadata dictionary
dcs = nx.degree_centrality(G)
for n in G.nodes():
    G.nodes[n]['centrality'] = dcs[n]

If you want a refresher on degree centrality, check out the relevant video from the previous course - it is a way of computing the importance of a node!

CircosPlot has been pre-imported for you from nxviz, along with NetworkX (as nx) and matplotlib.pyplot (as plt).

Instructions

100 XP
  • Plot the network G using a circos plot. To do this:
    • Create a CircosPlot object called c using the CircosPlot() function.
    • Use the node_color and node_grouping parameters of CircosPlot() to color and group the nodes by the keyword 'bipartite'
    • Use the node_order parameter of CircosPlot() to order the nodes by 'centrality'.
  • Draw c to the screen and display it.