LoslegenKostenlos loslegen

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

Kurs anzeigen

Anleitung zur Übung

  • 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.

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
____
Code bearbeiten und ausführen