def matrix_plotting(self, G): # Calculate the largest connected component subgraph: largest_ccs largest_ccs = sorted(nx.connected_component_subgraphs(G), key=lambda x: len(x))[-1] # Create the customized MatrixPlot object: h h = MatrixPlot(graph=largest_ccs) # Draw the MatrixPlot to the screen h.draw() plt.show()
print(len(g.nodes())) ################################# Task 1 (MatrixPlot) # Import necessary modules from nxviz import MatrixPlot import matplotlib.pyplot as plt # Calculate the largest connected component subgraph: largest_ccs largest_ccs = sorted(nx.connected_component_subgraphs(G), key=lambda x: len(x))[-1] # Create the customized MatrixPlot object: h h = MatrixPlot(graph=largest_ccs, node_grouping='grouping') # Draw the MatrixPlot to the screen h.draw() plt.show() ################################## Task 2 (ArcPlot) # Import necessary modules from nxviz.plots import ArcPlot import matplotlib.pyplot as plt # Iterate over all the nodes in G, including the metadata for n, d in G.nodes(data=True): # Calculate the degree of each node: G.node[n]['degree'] G.node[n]['degree'] = nx.degree(G, n) # Create the ArcPlot object: a a = ArcPlot(graph=G, node_order='degree')
from collections import Counter mf_count = Counter([gender[i - 1] for i in g1.nodes()]) def test_answer(mf_counts): assert mf_counts['female'] == 17 assert mf_counts['male'] == 12 test_answer(mf_count) from nxviz import MatrixPlot m = MatrixPlot(g) m.draw() plt.show() from nxviz import ArcPlot a = ArcPlot(g) a.draw() from nxviz import CircosPlot c = CircosPlot(g) c.draw() plt.show() # plt.savefig('images/seventh.png', dpi=300) #%% hiveplot