def communities(self, G):

        # Identify the largest maximal clique: largest_max_clique
        largest_max_clique = set(
            sorted(nx.find_cliques(G), key=lambda x: len(x))[-1])

        # Create a subgraph from the largest_max_clique: G_lmc
        G_lmc = G.subgraph(largest_max_clique).copy()

        # Go out 1 degree of separation
        for node in list(G_lmc.nodes()):
            G_lmc.add_nodes_from(G.neighbors(node))
            G_lmc.add_edges_from(
                zip([node] * len(list(G.neighbors(node))), G.neighbors(node)))

            # Record each node's degree centrality score
        for n in G_lmc.nodes():
            G_lmc.node[n]['degree centrality'] = nx.degree_centrality(G_lmc)[n]

        # Create the ArcPlot object: a
        a = ArcPlot(G_lmc, node_order='degree centrality')

        # Draw the ArcPlot to the screen
        a.draw()
        plt.show()
Exemple #2
0
def draw_graph(graph):
    # pos = graphviz_layout(graph, prog='twopi', args='')
    # plt.figure(figsize=(8, 8))
    # nx.draw(graph, pos, node_size=20, alpha=0.5, node_color="blue", with_labels=False)
    # plt.axis('equal')
    # plt.show()

    # options = {
    #     'node_color': 'black',
    #     'node_size': 50,
    #     'line_color': 'grey',
    #     'linewidths': 0,
    #     'width': 0.1,
    # }
    # nx.draw(graph, **options)
    # plt.show()

    # Assume we have a professional network of physicians belonging to hospitals.
    # c = CircosPlot(graph, node_color='university', node_grouping='university')
    c = ArcPlot(graph,
                node_color="country",
                node_grouping="university",
                group_order="alphabetically")
    c.draw()
    plt.show()  # only needed in scripts
    def arc_plotting(self, G):
        # 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
        a.draw()
        plt.show()
Exemple #4
0
################################## 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')

# Draw the ArcPlot to the screen
a.draw()
plt.show()

############################### Task 3 (CircosPlot)
# Import necessary modules
from nxviz import CircosPlot
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,
Exemple #5
0
"""
Displays a NetworkX lollipop graph to screen using a ArcPlot.
"""

import matplotlib.pyplot as plt
import networkx as nx
import numpy.random as npr

from nxviz.plots import ArcPlot

G = nx.lollipop_graph(m=10, n=4)
for n, d in G.nodes(data=True):
    G.node[n]['value'] = npr.normal()
c = ArcPlot(G, node_color='value', node_order='value')
c.draw()
plt.show()
'''
# 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()
'''
# 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')

# Draw the ArcPlot to the screen
a.draw()
plt.show()