Ejemplo n.º 1
0
    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()
Ejemplo n.º 2
0
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')

# 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)
Ejemplo n.º 3
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()
Ejemplo n.º 4
0
with open('../datasets/github_users_subsampled.p2', 'rb') as f:
    nodes, edges = pickle.load(f)
    G = nx.Graph()
    G.add_nodes_from(nodes)
    G.add_edges_from(edges)
'''
Instructions

*   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 (by specifying data=True).
    *   In each iteration of the loop, calculate the degree of each node n with nx.degree() and set its 'degree' attribute. nx.degree() accepts two arguments: A graph and a node.
    *   Create the ArcPlot object a by specifying two parameters: the graph, which is G, and the node_order, which is 'degree', so that the nodes are sorted.
    *   Draw the ArcPlot object to the screen.
'''

# 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()
Ejemplo n.º 5
0
/* Next up, let's use the ArcPlot to visualize the network. You're going to practice sorting the nodes in the graph as well.

Note: this exercise may take about 4-7 seconds to execute if done correctly. */

# 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(G, node_order = 'degree')

# Draw the ArcPlot to the screen
a.draw()
plt.show()
Ejemplo n.º 6
0
"""
Displays a NetworkX barbell graph to screen using a ArcPlot.
"""

from nxviz.plots import ArcPlot
from random import choice
import networkx as nx
import matplotlib.pyplot as plt

G = nx.barbell_graph(m1=10, m2=3)
for n, d in G.nodes(data=True):
    G.node[n]['class'] = choice(['one', 'two', 'three'])
c = ArcPlot(G, node_color="class", node_order='class')
c.draw()
plt.show()
Ejemplo n.º 7
0
############## Diameter is the maximium eccentricity of the graph
print(nx.radius(G))

###### Periphery of a graph is(are) set(s) of node whose eccentricity == diamenter
print(nx.periphery(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)
    G.node[n]["class"] = choice(["one", "two", "three"])
    G.node[n]['distance'] = nx.eccentricity(G, n)
    # G.node[n]['center'] = nx.radius(G)

a = ArcPlot(G, node_color="degree", node_order="distance", node_labels=True)
# Draw the ArcPlot to the screen
# print(G.node[3])
a.draw()
plt.axis('off')
plt.show()

###### Cemter nodes has eccentricity == radius
print(nx.center(G))  # sensitive to outlier node

# pos = nx.get_node_attributes(G, 'class')
pos = nx.kamada_kawai_layout(G)
nx.draw_networkx(G, pos)
plt.axis('off')
plt.show()
Ejemplo n.º 8
0
    }),
    ('B', {
        'n_visitors': '3'
    }),
    ('C', {
        'n_visitors': '4'
    }),
]

G.add_nodes_from(NODES_EBUNCH)

EDGES_EBUNCH = [
    ('A', 'B', 1),
    ('A', 'C', 2),
    ('B', 'C', 25),
    ('C', 'B', 10),
]

G.add_weighted_edges_from(EDGES_EBUNCH, )

edges = G.edges()

c = ArcPlot(G,
            node_labels=True,
            node_size='n_visitors',
            node_color='n_visitors',
            edge_width='weight')

c.draw()
plt.show()
Ejemplo n.º 9
0
"""
Displays different node_size with ArcPlot
"""

import matplotlib.pyplot as plt
import networkx as nx
from nxviz.plots import ArcPlot

G = nx.Graph()

G.add_node("A", score=1.5)
G.add_node("B", score=0.5)
G.add_node("C", score=1)


G.add_edge("A", "B", weight=8, type="a")
G.add_edge("A", "C", weight=8, type="b")
G.add_edge("B", "C", weight=8, type="a")


c = ArcPlot(G, node_size="score", edge_width="weight", edge_color="type")

c.draw()
plt.show()
Ejemplo n.º 10
0
    G = nx.Graph()
    G.add_edges_from(zip(df['doctor1'], df['doctor2']))

    return G


G = load_physicians_network()

# Make a CircosPlot, but with the nodes colored by their connected component
# subgraph ID.
ccs = nx.connected_component_subgraphs(G)
for i, g in enumerate(ccs):
    for n in g.nodes():
        G.node[n]['group'] = i
        G.node[n]['connectivity'] = G.degree(n)
m = CircosPlot(G,
               node_color='group',
               node_grouping='group',
               node_order='connectivity')
m.draw()
plt.show()

# Make an ArcPlot.
a = ArcPlot(G,
            node_color='group',
            node_grouping='group',
            node_order='connectivity')
a.draw()
plt.show()
Ejemplo n.º 11
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()
Ejemplo n.º 12
0
"""
Displays different edge_colors with ArcPlot
"""

import matplotlib.pyplot as plt
import networkx as nx
from nxviz.plots import ArcPlot

G = nx.Graph()

G.add_edge("A", "B", weight=8, type="a")
G.add_edge("A", "C", weight=8, type="b")
G.add_edge("B", "C", weight=8, type="a")

c = ArcPlot(G, edge_width="weight", edge_color="type")

c.draw()
plt.show()
Ejemplo n.º 13
0
"""
Displays a NetworkX octahedral graph to screen using a ArcPlot.
"""

import matplotlib.pyplot as plt
import networkx as nx

from nxviz.plots import ArcPlot

G = nx.octahedral_graph()
c = ArcPlot(G)
c.draw()
plt.show()
Ejemplo n.º 14
0
    G = nx.Graph()
    G.add_edges_from(zip(df["doctor1"], df["doctor2"]))

    return G


G = load_physicians_network()

# Make a CircosPlot, but with the nodes colored by their connected component
# subgraph ID.
ccs = nx.connected_component_subgraphs(G)
for i, g in enumerate(ccs):
    for n in g.nodes():
        G.node[n]["group"] = i
        G.node[n]["connectivity"] = G.degree(n)
m = CircosPlot(G,
               node_color="group",
               node_grouping="group",
               node_order="connectivity")
m.draw()
plt.show()

# Make an ArcPlot.
a = ArcPlot(G,
            node_color="group",
            node_grouping="group",
            node_order="connectivity")
a.draw()
plt.show()
Ejemplo n.º 15
0
'''
# 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()