How to use the nxviz.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 / tests / test_plots.py View on Github external
def test_edge_color():
    # add color as attribute and fill with random numbers
    edges = G.edges()
    for u, v in edges:
        G[u][v]["type"] = "a" if random() < 0.5 else "b"
    # also extract list for testing
    types = [G[u][v]["type"] for u, v in edges]
    # add color as property
    c = CircosPlot(G, edge_color="type")
    assert corresponding_lists(c.edge_colors, types)
    a = ArcPlot(G, edge_color="type")
    assert corresponding_lists(a.edge_colors, types)
github ericmjl / nxviz / tests / test_plots.py View on Github external
def test_circos_plot():
    c = CircosPlot(G)  # noqa: F841
    diff = diff_plots(c, "circos.png", baseline_dir, result_dir)
    assert diff is None
github ericmjl / nxviz / tests / test_plots.py View on Github external
def test_plot_size():
    c = CircosPlot(G, figsize=(3, 3))  # noqa: F841
    diff = diff_plots(c, "circos33.png", baseline_dir, result_dir)
    assert diff is None
github ericmjl / nxviz / tests / test_plots.py View on Github external
def test_edge_widths():
    # add weight as attribute and fill with random numbers
    edges = G.edges()
    for u, v in edges:
        G[u][v]["weight"] = random()
    # also extract list for testing
    weights = [G[u][v]["weight"] for u, v in edges]
    # add weights as property
    c = CircosPlot(G, edge_width="weight")
    assert c.edge_widths == weights
    a = ArcPlot(G, edge_width="weight")
    assert a.edge_widths == weights
    # add weights as list
    c = CircosPlot(G, edge_width=weights)
    assert c.edge_widths == weights
    a = ArcPlot(G, edge_width=weights)
    assert a.edge_widths == weights
github ericmjl / nxviz / examples / circos / number_labels.py View on Github external
"""
Shows how to rotate node labels. This increaes legibility for longer labels.
"""

import matplotlib.pyplot as plt
import networkx as nx

from nxviz import CircosPlot

G = nx.barbell_graph(m1=5, m2=3)
# let's give the nodes some longer labels
G = nx.relabel_nodes(G, {i: "long name #" + str(i) for i in range(len(G))})

# try it `node_label_layout=False` to see how the long names overlap each other
c = CircosPlot(G, node_labels=True, node_label_layout="numbers")
c.node_colors = ["skyblue" for node_color in c.node_colors]
c.draw()
# the rotated labels take up more space, so we will have to increase the
# padding a bit. 15% on all sides works well here.
plt.tight_layout(rect=(0.15, 0.15, 0.85, 0.85))
plt.show()
github AmoDinho / datacamp-python-data-science-track / Network Analysis in Python (Part 1) / Chapter 1 - Introduction to networks.py View on Github external
# Convert A back to the NetworkX form as a directed graph: T_conv
T_conv = nx.from_numpy_matrix(A, create_using=nx.DiGraph())

# Check that the `category` metadata field is lost from each node
for n, d in T_conv.nodes(data=True):
    assert 'category' not in d.keys()
#---------=======================================================--------------%

#Visualizing using Circos plots
# 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()

#---------=======================================================--------------%



#Visualizing using Arc plots
# Import necessary modules
import matplotlib.pyplot as plt
from nxviz import ArcPlot
github ericmjl / nxviz / examples / circos / change_font.py View on Github external
"""
Shows how to rotate node labels. This increaes legibility for longer labels.
"""

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

G = nx.barbell_graph(m1=20, m2=3)
for n, d in G.nodes(data=True):
    G.node[n]["class"] = choice(["one", "two", "three", "four", "five"])

c = CircosPlot(
    G,
    node_grouping="class",
    node_color="class",
    node_order="class",
    group_label_position="middle",
    nodeprops={"radius": 1},
    node_label_layout="rotation",
    fontsize=12,
    fontfamily="fantasy",
)
c.draw()
plt.show()
github ericmjl / nxviz / examples / circos / rotate_labels.py View on Github external
"""
Shows how to rotate node labels. This increaes legibility for longer labels.
"""

import matplotlib.pyplot as plt
import networkx as nx

from nxviz import CircosPlot

G = nx.barbell_graph(m1=20, m2=3)
# let's give the nodes some longer labels
G = nx.relabel_nodes(G, {i: "long name " + str(i) for i in range(len(G))})

# try it `node_label_layout=False` to see how the long names overlap each other
c = CircosPlot(G, node_labels=True, node_label_layout="rotation")
c.draw()
# the rotated labels take up more space, so we will have to increase the
# padding a bit. 15% on all sides works well here.
plt.tight_layout(rect=(0.15, 0.15, 0.85, 0.85))
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
#---------=======================================================--------------%
#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, node_order='degree', node_grouping='grouping', node_color='grouping')

# Draw the CircosPlot object to the screen
c.draw()
plt.show()

#---------=======================================================--------------%
#Finding cliques (I)
# Calculate the maximal cliques in G: cliques
cliques = nx.find_cliques(G)

# Count and print the number of maximal cliques in G
print(len(list(cliques)))



#---------=======================================================--------------%
github AmoDinho / datacamp-python-data-science-track / Network Analysis in Python (Part 1) / Chapter 4 - Bringing it all together.py View on Github external
#Finding cliques (II)

# Import necessary modules
import networkx as nx
from nxviz import CircosPlot
import matplotlib.pyplot as plt

# 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()



#---------=======================================================--------------%

#Finding important collaborators
# Compute the degree centralities of G: deg_cent
deg_cent = nx.degree_centrality(G)

# Compute the maximum degree centrality: max_dc
max_dc = max(deg_cent.values())