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).
Este exercício faz parte do curso
Intermediate Network Analysis in Python
Instruções do exercício
- Plot the network
Gusing a circos plot. To do this:- Create a
circosplot calledcusing thenv.circos()function. You have to specify the parametersgraphandnode_color_byandgroup_bykeyword arguments to color and group nodes by their keywordbipartite, and thesort_byargument 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
cto the screen.
- Create a
Exercício interativo prático
Experimente este exercício completando este código de exemplo.
# Create the CircosPlot object: c
c = nv._____(___, _____, _____, node_enc_kwargs={'radius': 10})
# Display the plot
____