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
).
Diese Übung ist Teil des Kurses
Intermediate Network Analysis in Python
Anleitung zur Übung
- 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
Interaktive Übung
Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.
# Create the CircosPlot object: c
c = nv._____(___, _____, _____, node_enc_kwargs={'radius': 10})
# Display the plot
____