NetworkX¶
NetworkX graphs can be added to a canvas in the following way:
import networkx as nx
from algorithmx.networkx import add_graph
G = nx.MultiDiGraph()
G.add_nodes_from([1, 2, 3])
G.add_weighted_edges_from([(1, 2, 3.0), (2, 3, 7.5)])
# canvas = ...
add_graph(canvas, G)
-
algorithmx.networkx.
add_graph
(canvas: algorithmx.api.Canvas.Canvas, graph, weight: Optional[str] = 'weight') → algorithmx.api.Canvas.Canvas[source]¶ Adds all nodes and edges from a NetworkX graph to the given canvas. Edges will automatically set the
directed()
attribute and/or add a weightlabel()
depending on the provided graph.- Parameters
canvas (
Canvas
) – The canvas onto which the graph should be added.graph (Any type of NetworkX graph) – The NetworkX graph.
weight (Union[str, None]) – The name of the attribute which describes edge weight in the NetworkX graph. Edges without the attribute will not display a weight, and a value of
None
will prevent any weight from being displayed. Defaults to “weight”.
- Returns
The provided CanvasSelection with animations disabled, allowing initial attributes to be configured.
- Return type
CanvasSelection