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()
list(nx.connected_component_subgraph(G)) for g in list(nx.connected_component_subgraph(G)): 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)
# MatrixPlot visualization of the largest connected component subgraph, # with authors grouped by their user group number. # ### Task IMplementation ###### # Create the MatrixPlot object h. You have to specify the parameters # "graph" and "node_grouping" to be the largest connected component subgraph # and 'grouping', respectively. # 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(largest_ccs, 'grouping') # Draw the MatrixPlot to the screen h.draw() plt.show() #%% # ########## Arc Plot ########### # Make an ArcPlot of the GitHub collaboration network, # with authors sorted by degree. To do this: # Iterate over all the nodes in G, including the metadata for n, d in G.nodes(data=True):
def test_matrix_plot(): m = MatrixPlot(G) # noqa: F841 diff = diff_plots(m, "matrix.png", baseline_dir, result_dir) assert diff is None
## Quick draw of G nx.draw(G, with_labels=True) plt.show() # Graph properties G.nodes() len(G.edges()) len(G.nodes()) ## Degree centrality and betweenne centrality nx.degree_centrality(G) # Returns a dictionary plt.hist(list(nx.degree_centrality(G).values())) plt.show() nx.betweenness_centrality(G) plt.hist(list(nx.betweenness_centrality(G).values())) plt.show() # Visualizatio largest_ccs = sorted(nx.connected_component_subgraphs(G), key=lambda x: len(x))[-1] h = MatrixPlot(graph=G) h.draw() plt.show() nx.degree(G) nx.draw(G, with_labels=True) plt.show()
def test_matrix_plot(): m = MatrixPlot(G) # noqa: F841
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)
def test_matrix_plot(): m = MatrixPlot(G)
from itertools import combinations from collections import defaultdict graph = pickle.load(open('github_users.p', 'rb')) print("no. of users: " + str(len(graph.nodes()))) print("no. of user-collaborations(p2p) : " + str(len(graph.edges()))) plt.hist(list(nx.degree_centrality(graph).values())) plt.show() # Calculate the largest connected component subgraph largest_ccs = sorted(nx.connected_component_subgraphs(graph), key=lambda x: len(x))[-1] h = MatrixPlot(largest_ccs) h.draw() plt.show() for n, d in graph.nodes(data=True): graph.node[n]['degree'] = nx.degree(graph, n) # a = ArcPlot(graph=graph, node_order='degree') # a.draw() # plt.show() # Calculate the maximal cliques in G cliques = nx.find_cliques(graph)
#obseravation:- we can clearly observe positive correlation between degrees and degree centrality of network # Compute the betweenness centrality of G: bet_cen bet_cen = nx.betweenness_centrality(G) # Create a scatter plot of betweenness centrality and degree centrality plt.scatter(list(bet_cen.values()), list(deg_cent.values())) # Display the plot plt.show() # 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() # 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') # Draw the ArcPlot to the screen