networkx 2.8.2 Pypi GitHub Homepage
Other Docs

The ordered variants of graph classes in this module are deprecated and will be removed in version 3.0.

Consistently ordered variants of the default base classes. Note that if you are using Python 3.6+, you shouldn't need these classes because the dicts in Python 3.6+ are ordered. Note also that there are many differing expectations for the word "ordered" and that these classes may not provide the order you expect. The intent here is to give a consistent order not a particular order.

The Ordered (Di/Multi/MultiDi) Graphs give a consistent order for reporting of nodes and edges. The order of node reporting agrees with node adding, but for edges, the order is not necessarily the order that the edges were added.

In general, you should use the default (i.e., unordered) graph classes. However, there are times (e.g., when testing) when you may need the order preserved.

Special care is required when using subgraphs of the Ordered classes. The order of nodes in the subclass is not necessarily the same order as the original class. In general it is probably better to avoid using subgraphs and replace with code similar to:

.. code-block:: python
    # instead of SG = G.subgraph(ordered_nodes)
    SG = nx.OrderedGraph()
    SG.add_nodes_from(ordered_nodes)
    SG.add_edges_from((u, v) for (u, v) in G.edges() if u in SG if v in SG)
deprecated
deprecated

The ordered variants of graph classes in this module are deprecated and will be removed in version 3.0.

Consistently ordered variants of the default base classes. Note that if you are using Python 3.6+, you shouldn't need these classes because the dicts in Python 3.6+ are ordered. Note also that there are many differing expectations for the word "ordered" and that these classes may not provide the order you expect. The intent here is to give a consistent order not a particular order.

The Ordered (Di/Multi/MultiDi) Graphs give a consistent order for reporting of nodes and edges. The order of node reporting agrees with node adding, but for edges, the order is not necessarily the order that the edges were added.

In general, you should use the default (i.e., unordered) graph classes. However, there are times (e.g., when testing) when you may need the order preserved.

Special care is required when using subgraphs of the Ordered classes. The order of nodes in the subclass is not necessarily the same order as the original class. In general it is probably better to avoid using subgraphs and replace with code similar to:

.. code-block:: python
    # instead of SG = G.subgraph(ordered_nodes)
    SG = nx.OrderedGraph()
    SG.add_nodes_from(ordered_nodes)
    SG.add_edges_from((u, v) for (u, v) in G.edges() if u in SG if v in SG)

Examples

See :

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


GitHub : /networkx/classes/ordered.py#0
type: <class 'module'>
Commit: