How to use the nxviz.plots.ArcPlot function in nxviz

To help you get started, we’ve selected a few nxviz examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ericmjl / nxviz / examples / datasets / physician.py View on Github external
# 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()
github AmoDinho / datacamp-python-data-science-track / Network Analysis in Python (Part 1) / Chapter 4 - Bringing it all together.py View on Github external
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)

# Go out 1 degree of separation
for node in G_lmc.nodes():
    G_lmc.add_nodes_from(G.neighbors(node))
    G_lmc.add_edges_from(zip([node]*len(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()

#---------=======================================================--------------%
#Recommending co-editors who have yet to edit together
# Import necessary modules
from itertools import combinations
from collections import defaultdict

# Initialize the defaultdict: recommended
recommended = defaultdict(int)

# Iterate over all the nodes in G
for n, d in G.nodes(data=True):
github ericmjl / nxviz / examples / arc / node_size.py View on Github external
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()
github ericmjl / nxviz / examples / arc / barbell.py View on Github external
"""
Displays a NetworkX barbell graph to screen using a ArcPlot.
"""

from random import choice

import matplotlib.pyplot as plt
import networkx as nx

from nxviz.plots import ArcPlot

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()
github ericmjl / nxviz / nxviz / plots.py View on Github external
def draw(self):
        super(ArcPlot, self).draw()

        left_limit = self.node_sizes[0]
        right_limit = sum(r for r in self.node_sizes)
        xlimits = (-left_limit, right_limit + 1)
        self.ax.set_xlim(*xlimits)
        self.ax.set_ylim(*xlimits)
github ericmjl / nxviz / examples / arc / octahedral.py View on Github external
"""
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()
github ericmjl / nxviz / examples / arc / lollipop.py View on Github external
"""
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()
github ericmjl / nxviz / examples / arc / edge_color.py View on Github external
"""
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()
github ericmjl / nxviz / examples / arc / edge_width.py View on Github external
NODES_EBUNCH = [
    ("A", {"n_visitors": "1"}),
    ("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()
github AmoDinho / datacamp-python-data-science-track / Network Analysis in Python (Part 1) / Chapter 4 - Bringing it all together.py View on Github external
#---------=======================================================--------------%
#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()


#---------=======================================================--------------%
#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']