Object-Oriented API
For those who may prefer the object-oriented API of the past, we provide the following class definitions that map directly to the functions.
%config InlineBackend.figure_format = 'retina'
%load_ext autoreload
%autoreload 2
from random import choice
import matplotlib.pyplot as plt
import networkx as nx
import numpy as np
import nxviz as nv
from nxviz import annotate
from nxviz.plots import despine, rescale, respine
Example Graph
We're going to use an example graph, the erdos-renyi graph, to illustrate.
Source code
G = nx.erdos_renyi_graph(n=71, p=0.1)
for n, d in G.nodes(data=True):
G.nodes[n]["group"] = choice(["a", "b", "c"])
G.nodes[n]["value"] = np.random.exponential()
np.random.seed(44)
for u, v, d in G.edges(data=True):
G.edges[u, v]["edge_value"] = np.random.exponential()
API Examples
The API from pre-0.7 is mostly preserved as a way
to help users who learned the object-oriented API transition over.
A key difference here is that instantiating the object
and then calling .draw()
is no longer necessary.
Additionally, annotation logic has been moved out of the class definitions
and are now available as part of the annotations submodule.
Because the API is no longer being officially supported, these will be officially deprecated in version 1.0. A warning message will show up the first time you try to access any of the objects provided. PRs that try to add an object version of a plot will also be rejected.
nv.HivePlot(G, node_grouping="group", node_color="value", node_order="value", edge_alpha="edge_value")
from nxviz import annotate
annotate.hive_group(G, group_by="group", offset=np.pi / 12)
nv.CircosPlot(G, node_grouping="group", node_color="value", node_order="value")
nv.MatrixPlot(G, node_grouping="group", node_color="value", node_order="value")
nv.ArcPlot(
G,
node_grouping="group",
node_color="value",
node_order="value",
edge_color="edge_value",
)
annotate.arc_group(G, group_by="group", rotation=0)