networkx 2.8.2 Pypi GitHub Homepage
Other Docs

To remove in the future –– networkx.classes.reportviews

View Classes provide node, edge and degree "views" of a graph.

Views for nodes, edges and degree are provided for all base graph classes. A view means a read-only object that is quick to create, automatically updated when the graph changes, and provides basic access like :None:None:`n in V`, :None:None:`for n in V`, :None:None:`V[n]` and sometimes set operations.

The views are read-only iterable containers that are updated as the graph is updated. As with dicts, the graph should not be updated while iterating through the view. Views can be iterated multiple times.

Edge and Node views also allow data attribute lookup. The resulting attribute dict is writable as :None:None:`G.edges[3, 4]['color']='red'` Degree views allow lookup of degree values for single nodes. Weighted degree is supported with the :None:None:`weight` argument.

NodeView

:None:None:`V = G.nodes` (or :None:None:`V = G.nodes()`) allows :None:None:`len(V)`, :None:None:`n in V`, set operations e.g. "G.nodes & H.nodes", and :None:None:`dd = G.nodes[n]`, where :None:None:`dd` is the node data dict. Iteration is over the nodes by default.

NodeDataView

To iterate over (node, data) pairs, use arguments to :None:None:`G.nodes()` to create a DataView e.g. :None:None:`DV = G.nodes(data='color', default='red')`. The DataView iterates as :None:None:`for n, color in DV` and allows :None:None:`(n, 'red') in DV`. Using :None:None:`DV = G.nodes(data=True)`, the DataViews use the full datadict in writeable form also allowing contain testing as :None:None:`(n, {'color': 'red'}) in VD`. DataViews allow set operations when data attributes are hashable.

DegreeView

:None:None:`V = G.degree` allows iteration over (node, degree) pairs as well as lookup: :None:None:`deg=V[n]`. There are many flavors of DegreeView for In/Out/Directed/Multi. For Directed Graphs, :None:None:`G.degree` counts both in and out going edges. :None:None:`G.out_degree` and :None:None:`G.in_degree` count only specific directions. Weighted degree using edge data attributes is provide via :None:None:`V = G.degree(weight='attr_name')` where any string with the attribute name can be used. :None:None:`weight=None` is the default. No set operations are implemented for degrees, use NodeView.

The argument nbunch restricts iteration to nodes in nbunch. The DegreeView can still lookup any node even if nbunch is specified.

EdgeView

:None:None:`V = G.edges` or :None:None:`V = G.edges()` allows iteration over edges as well as :None:None:`e in V`, set operations and edge data lookup :None:None:`dd = G.edges[2, 3]`. Iteration is over 2-tuples :None:None:`(u, v)` for Graph/DiGraph. For multigraphs edges 3-tuples :None:None:`(u, v, key)` are the default but 2-tuples can be obtained via :None:None:`V = G.edges(keys=False)`.

Set operations for directed graphs treat the edges as a set of 2-tuples. For undirected graphs, 2-tuples are not a unique representation of edges. So long as the set being compared to contains unique representations of its edges, the set operations will act as expected. If the other set contains both :None:None:`(0, 1)` and :None:None:`(1, 0)` however, the result of set operations may contain both representations of the same edge.

EdgeDataView

Edge data can be reported using an EdgeDataView typically created by calling an EdgeView: :None:None:`DV = G.edges(data='weight', default=1)`. The EdgeDataView allows iteration over edge tuples, membership checking but no set operations.

Iteration depends on :None:None:`data` and default and for multigraph keys If :None:None:`data is False` (the default) then iterate over 2-tuples :None:None:`(u, v)`. If :None:None:`data is True` iterate over 3-tuples :None:None:`(u, v, datadict)`. Otherwise iterate over :None:None:`(u, v, datadict.get(data, default))`. For Multigraphs, if :None:None:`keys is True`, replace :None:None:`u, v` with :None:None:`u, v, key` to create 3-tuples and 4-tuples.

The argument nbunch restricts edges to those incident to nodes in nbunch.

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/reportviews.py#0
type: <class 'module'>
Commit: