How to use the nxviz.MatrixPlot 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_matrix_plot():
    m = MatrixPlot(G)  # noqa: F841
    diff = diff_plots(m, "matrix.png", baseline_dir, result_dir)
    assert diff is None
github AmoDinho / datacamp-python-data-science-track / Network Analysis in Python (Part 1) / Chapter 1 - Introduction to networks.py View on Github external
return nodes_in_selfloops

# Check whether number of self loops equals the number of nodes in self loops
assert T.number_of_selfloops() == len(find_selfloop_nodes(T))




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

#Visualizing using Matrix plots
# Import nxviz
import nxviz as nv

# Create the MatrixPlot object: m
m = nv.MatrixPlot(T)

# Draw m to the screen
m.draw()

# Display the plot
plt.show()

# Convert T to a matrix format: A
A = nx.to_numpy_matrix(T)

# 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()
github AmoDinho / datacamp-python-data-science-track / Network Analysis in Python (Part 1) / Chapter 4 - Bringing it all together.py View on Github external
plt.hist(list(nx.betweenness_centrality(G).values()))
plt.show()


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

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

#Great work! Recall that in a MatrixPlot, nodes are the rows and columns of the matrix, and cells are filled ine filled in according to whether an edge exists between the pairs of nodes. according to wheth
#---------=======================================================--------------%
#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):