Utilities

NetworkX

NetworkX graphs can be directly 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.graphics.CanvasSelection.CanvasSelection, graph, weight: Optional[str] = 'weight') → algorithmx.graphics.CanvasSelection.CanvasSelection[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 weight label() depending on the provided graph.

Parameters
  • canvas (CanvasSelection) – The CanvasSelection 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 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