def maximal_clique(self, G): # Find the author(s) that are part of the largest maximal clique: largest_clique largest_clique = sorted(nx.find_cliques(G), key=lambda x: len(x))[-1] # Create the subgraph of the largest_clique: G_lc G_lc = G.subgraph(largest_clique) # Create the CircosPlot object: c c = CircosPlot(G_lc) # Draw the CircosPlot to the screen c.draw() plt.show()
def circos_plotting(self, G): # Iterate over all the nodes, 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 CircosPlot object: c c = CircosPlot(graph=G, node_order='degree') # Draw the CircosPlot object to the screen c.draw() plt.show()
import matplotlib.pyplot as plt # Iterate over all the nodes, 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 CircosPlot object: c c = CircosPlot(G, node_order='degree', node_grouping='grouping', node_color='grouping') # Draw the CircosPlot object to the screen c.draw() plt.show() ############################## Cliques #################################### import networkx as nx G = nx.erdos_renyi_graph(n=200, p=0.15) nx.find_cliques(G) for clique in nx.find_cliques(G): print(len(clique)) ############################## Task 1 (Finding cliques (I)) # Calculate the maximal cliques in G: cliques cliques = nx.find_cliques(G)
def circos_plot(G): """Draw a Circos Plot of the graph.""" c = CircosPlot(G, node_order="order", node_color="order") c.draw()
''' Visualizing using Circos plots Circos plots are a rational, non-cluttered way of visualizing graph data, in which nodes are ordered around the circumference in some fashion, and the edges are drawn within the circle that results, giving a beautiful as well as informative visualization about the structure of the network. In this exercise, you'll continue getting practice with the nxviz API, this time with the CircosPlot object. matplotlib.pyplot has been imported for you as plt. INSTRUCTIONS 100XP Import CircosPlot from nxviz. Plot the Twitter network T as a Circos plot without any styling. Use the CircosPlot() function to do this. Don't forget to draw it to the screen using .draw() and then display it using plt.show(). ''' # Import necessary modules import matplotlib.pyplot as plt from nxviz import CircosPlot # Create the CircosPlot object: c c = CircosPlot(T) # Draw c to the screen c.draw() # Display the plot plt.show()
def plot_cc_subgraph(G): """Plot all connected component subgraphs.""" c = CircosPlot(G, node_color="subgraph", node_order="subgraph") c.draw()
def plot_graph_circos(graph, sc_threshold=0.07): # Some parts of the code from: # https://github.com/multinetlab-amsterdam/network_TDA_tutorial G = graph.copy() # remove weak connections for edge in nx.get_edge_attributes(G, 'weight').items(): if edge[1] < sc_threshold: G.remove_edge(edge[0][0], edge[0][1]) atlas = atlases.AutomatedAnatomicalParcellation2() atlas = aal2_atlas_add_cortical_regions(atlas) G = nx.relabel_nodes(G, lambda x: atlas.names('cortex')[x]) sublist = {} order = {} n = 0 for group in list(CORTICAL_REGIONS.keys()): for i in atlas.names(group=group): sublist[i] = group if i[-1] == 'L': order[i] = n else: order[i] = n + 1 n += 2 nx.set_node_attributes(G, sublist, 'cortical_region') nx.set_node_attributes(G, order, 'node_order') # https://nxviz.readthedocs.io/en/latest/modules.html circ = CircosPlot(G, figsize=(15, 15), node_labels=True, node_label_layout='rotation', edge_color='weight', edge_width='weight', fontsize=10, node_order='node_order', nodeprops={"radius": 1}, group_label_offset=5, node_color='cortical_region', group_legend=True) circ.draw() circ.sm.colorbar.remove() labels_networks = sorted( list( set([ list(circ.graph.nodes.values())[n][circ.node_color] for n in np.arange(len(circ.nodes)) ]))) plt.legend(handles=circ.legend_handles, title="Subnetwork", ncol=2, borderpad=1, shadow=True, fancybox=True, bbox_to_anchor=(0.8, 1.05), loc='upper left', fontsize=10, labels=labels_networks) plt.tight_layout() return circ
#plt.show() plt.savefig('./figures/Matrixplot_credit_transaction.png') x = nx.adj_matrix(G_conv) print(x.todense()) ## Cercoplot from nxviz import CircosPlot Mat = CircosPlot(G, node_labels=True, node_order='Y', font_size=32, node_color='C', figsize=(8, 8), font_weight='bold') # This creates a circosplot object Mat. Mat.draw() plt.savefig('./figures/Cerco_credit_transaction.png') plt.show() ## Arcplot from nxviz import ArcPlot Mat = ArcPlot(G, node_labels=True, font_size=25, node_order='Y', node_color='C', figsize=(8, 8)) Mat.draw() plt.savefig('./figures/Arc_credit_transaction.png') plt.show()
# Import necessary modules to use Circos plot import matplotlib.pyplot as plt from nxviz import CircosPlot # Create the CircosPlot object - CBLOL c = CircosPlot(G_CBLOL, node_size = size_from_wins_cblol, node_labels=True, figsize = (15,15), nodeprops={"radius": 0.5}, fontsize=12 ) # Draw c to the screen c.draw() c.figure.tight_layout() # Display the plot plt.show() # Create the CircosPlot object - MSI m = CircosPlot(G_MSI, node_size = size_from_wins_msi, node_labels=True, figsize = (15,15), nodeprops={"radius": 0.5}, fontsize=12 )
cen_clos = nx.closeness_centrality(H) cc = nx.clustering(H) for v in H.nodes(): node = H.nodes[v] node['degree'] = deg_cen[v] node['betweeness'] = cen_btw[v] node['eigenvector'] = cen_ei[v] node['closeness'] = cen_clos[v] node['clustering'] = float(cc[v]) # --------------- # --- PLOTTING --- indexes = ['degree', 'betweeness', 'eigenvector', 'closeness', 'clustering'] for i in indexes: current = CircosPlot(H, title=i, node_color=i, node_order=i, node_labels=True) current.draw() plt.title(i.capitalize()) plt.suptitle(i.capitalize()) plt.savefig(f"output/{i}.png") # ---------------