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
Exercise instructions
- Plot the network
G
using a circos plot. To do this:- Create a
circos
plot calledc
using thenv.circos()
function. You have to specify the parametersgraph
andnode_color_by
andgroup_by
keyword arguments to color and group nodes by their keywordbipartite
, and thesort_by
argument to order the nodes bycentrality
. - To ensure that the nodes are visible when displayed, we have included the argument
node_enc_kwargs={'radius': 10}
. - Draw
c
to the screen.
- Create a
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
____