Get startedGet started for free

Plotting using nxviz

Now, you're going to practice creating a circos plot 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!

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

This exercise is part of the course

Intermediate Network Analysis in Python

View Course

Exercise instructions

  • Plot the network G using a circos plot. To do this:
    • Create a circos plot called c using the nv.circos() function. You have to specify the parameters graph and node_color_by and group_by keyword arguments to color and group nodes by their keyword bipartite, and the sort_by argument to order the nodes by centrality.
    • To ensure that the nodes are visible when displayed, we have included the argument node_enc_kwargs={'radius': 10}.
    • Draw c to the screen.

Hands-on interactive exercise

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

# Create the CircosPlot object: c
c = nv._____(___, _____, _____, node_enc_kwargs={'radius': 10})

# Display the plot
____
Edit and Run Code