How to use the nxviz.plots.CircosPlot 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 / circos / group_labels_with_custom_legend.py View on Github external
from random import choice

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

G = nx.barbell_graph(m1=10, m2=3)
for n, d in G.nodes(data=True):
    G.node[n]["class"] = choice(["a", "b", "c", "d", "e"])

c = CircosPlot(
    G,
    node_grouping="class",
    node_color="class",
    node_order="class",
    node_labels=True,
    node_label_rotation=True,
    node_label_color=True,
    group_label_color=True,
    node_label_layout='numbers',
    group_order='alphabetically',
    fontsize=10,
    group_legend=True,
    figsize=(12, 12)
)

# Draw the CircosPlot
github ericmjl / nxviz / examples / circos / group_labels.py View on Github external
from random import choice

import matplotlib.pyplot as plt
import networkx as nx

from nxviz.plots import CircosPlot

G = nx.barbell_graph(m1=10, m2=3)
for n, d in G.nodes(data=True):
    G.node[n]["class"] = choice(["a", "b", "c", "d", "e"])
c = CircosPlot(
    G,
    node_grouping="class",
    node_color="class",
    node_order="class",
    node_labels=True,
    group_label_position="middle",
    group_label_color=True,
    group_label_offset=2,
)
c.draw()
plt.show()
github ericmjl / nxviz / examples / circos / edge_color.py View on Github external
("e", "d", {"weight": 0.8}),
    ("e", "f", {"weight": 1.0}),
]
edgelist2 = [
    ("a", "b", {"class": 1}),
    ("a", "c", {"class": 3}),
    ("b", "d", {"class": 8}),
    ("c", "d", {"class": 10}),
    ("e", "d", {"class": 5}),
    ("e", "f", {"class": 5}),
]

G = nx.Graph()
G.add_nodes_from(nodelist)
G.add_edges_from(edgelist1)
c = CircosPlot(graph=G, edge_color="weight")
c.draw()


F = nx.Graph()
F.add_nodes_from(nodelist)
F.add_edges_from(edgelist2)
d = CircosPlot(graph=F, edge_color="class")
d.draw()

plt.show()
github ericmjl / nxviz / examples / circos / octahedral.py View on Github external
"""
Displays a NetworkX octahedral graph to screen using a CircosPlot.
"""

import matplotlib.pyplot as plt
import networkx as nx

from nxviz.plots import CircosPlot

G = nx.octahedral_graph()
c = CircosPlot(G)
c.draw()
plt.show()
github ericmjl / nxviz / examples / circos / barbell.py View on Github external
"""
Displays a NetworkX barbell graph to screen using a CircosPlot.
"""

from random import choice

import matplotlib.pyplot as plt
import networkx as nx

from nxviz.plots import CircosPlot

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 = CircosPlot(G, node_color="class", node_order="class", node_labels=True)
c.draw()
plt.show()
github ericmjl / nxviz / nxviz / plots.py View on Github external
# Node labels are specified in the node_label_layout argument
        specified_layout = kwargs.pop("node_label_layout", None)
        # Verify that the provided input is legitimate
        valid_node_label_layouts = (None, "rotation", "numbers")
        assert specified_layout in valid_node_label_layouts
        # Store the node label layout
        self.node_label_layout = specified_layout

        # Group labels' radius can be offset by a certain amount
        group_label_offset = kwargs.pop("group_label_offset", 0)
        assert group_label_offset >= 0
        # Store the group label offset
        self.group_label_offset = group_label_offset

        #
        super(CircosPlot, self).__init__(graph, **kwargs)

        # Add legend to plot
        if "group_legend" in kwargs.keys():
            if kwargs["group_legend"]:
                self.draw_legend()
github ericmjl / nxviz / examples / datasets / crime.py View on Github external
node_grouping="bipartite",
    node_order="connectivity",
    node_color="bipartite",
)
c.draw()


# Make the "people" projection of the bipartite graph.
person_nodes = [n for n in G.nodes() if G.node[n]["bipartite"] == "person"]
pG = nx.bipartite.projection.projected_graph(G, person_nodes)

for n in pG.nodes():
    dcs = nx.degree_centrality(pG)
    pG.node[n]["connectivity"] = dcs[n]

c = CircosPlot(
    pG, node_grouping="gender", node_order="connectivity", node_color="gender"
)
c.draw()
plt.show()
github ericmjl / nxviz / examples / circos / edge_width.py View on Github external
"""
Shows different edge widths on CircusPlot
"""
import matplotlib.pyplot as plt
import networkx as nx
from nxviz.plots import CircosPlot

nodelist = [("a"), ("b"), ("c"), ("d"), ("e"), ("f")]
edgelist1 = [("a", "b"), ("b", "c"), ("c", "d"), ("d", "e"), ("e", "f")]

weights = list(range(6))

G = nx.Graph()
G.add_nodes_from(nodelist)
G.add_edges_from(edgelist1)
c = CircosPlot(graph=G, edge_width=weights)
c.draw()

plt.show()
github ericmjl / nxviz / examples / datasets / crime.py View on Github external
for n, gender_code in gender.iterrows():
        nodeid = "p{0}".format(n)
        G.node[nodeid]["gender"] = gender_code[0]

    return G


G = load_crime_network()

# Annotate each node with connectivity score
for n in G.nodes():
    dcs = nx.degree_centrality(G)
    G.node[n]["connectivity"] = dcs[n]

# Make a CircosPlot of the bipartite graph
c = CircosPlot(
    G,
    node_grouping="bipartite",
    node_order="connectivity",
    node_color="bipartite",
)
c.draw()


# Make the "people" projection of the bipartite graph.
person_nodes = [n for n in G.nodes() if G.node[n]["bipartite"] == "person"]
pG = nx.bipartite.projection.projected_graph(G, person_nodes)

for n in pG.nodes():
    dcs = nx.degree_centrality(pG)
    pG.node[n]["connectivity"] = dcs[n]
github ericmjl / nxviz / examples / datasets / physician.py View on Github external
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()