This densely packed View allows iteration over edges, data lookup like a dict and set operations on edges represented by node-tuples. In addition, edge data can be controlled by calling this object possibly creating an EdgeDataView. Typically edges are iterated over and reported as :None:None:`(u, v)` node tuples or :None:None:`(u, v, key)` node/key tuples for multigraphs. Those edge representations can also be using to lookup the data dict for any edge. Set operations also are available where those tuples are the elements of the set. Calling this object with optional arguments :None:None:`data`, default
and keys
controls the form of the tuple (see EdgeDataView). Optional argument nbunch
allows restriction to edges only involving certain nodes.
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` above.
A EdgeView class for edges of a Graph
>>> G = nx.path_graph(4)
... EV = G.edges()
... (2, 3) in EV True
>>> for u, v in EV:
... print((u, v)) (0, 1) (1, 2) (2, 3)
>>> assert EV & {(1, 2), (3, 4)} == {(1, 2)}
>>> EVdata = G.edges(data="color", default="aqua")
... G.add_edge(2, 3, color="blue")
... assert (2, 3, "blue") in EVdata
... for u, v, c in EVdata:
... print(f"({u}, {v}) has color: {c}") (0, 1) has color: aqua (1, 2) has color: aqua (2, 3) has color: blue
>>> EVnbunch = G.edges(nbunch=2)
... assert (2, 3) in EVnbunch
... assert (0, 1) not in EVnbunch
... for u, v in EVnbunch:
... assert u == 2 or v == 2
>>> MG = nx.path_graph(4, create_using=nx.MultiGraph)
... EVmulti = MG.edges(keys=True)
... (2, 3, 0) in EVmulti True
>>> (2, 3) in EVmulti # 2-tuples work even when keys is True True
>>> key = MG.add_edge(2, 3)See :
... for u, v, k in EVmulti:
... print((u, v, k)) (0, 1, 0) (1, 2, 0) (2, 3, 0) (2, 3, 1)
The following pages refer to to this document either explicitly or contain code examples using this.
networkx.classes.reportviews.EdgeDataViewnetworkx.convert_matrix.from_numpy_matrixnetworkx.classes.digraph.DiGraphnetworkx.readwrite.adjlist.parse_adjlistnetworkx.classes.digraph.DiGraph.remove_nodenetworkx.algorithms.tree.coding.to_prufer_sequencenetworkx.algorithms.assortativity.connectivity.average_degree_connectivitynetworkx.classes.graph.Graphnetworkx.classes.digraph.DiGraph.clear_edgesnetworkx.algorithms.bipartite.projection.weighted_projected_graphnetworkx.algorithms.operators.binary.unionnetworkx.classes.digraph.DiGraph.clearnetworkx.readwrite.edgelist.parse_edgelistnetworkx.classes.reportviews.EdgeViewnetworkx.algorithms.bipartite.edgelist.read_edgelistnetworkx.algorithms.operators.binary.composenetworkx.algorithms.bipartite.edgelist.parse_edgelistnetworkx.convert_matrix.from_numpy_arraynetworkx.generators.classic.circulant_graphnetworkx.classes.graph.Graph.clear_edgesnetworkx.classes.graph.Graph.clearnetworkx.generators.line.line_graphnetworkx.algorithms.bipartite.projection.collaboration_weighted_projected_graphnetworkx.classes.multidigraph.MultiDiGraphnetworkx.readwrite.edgelist.read_edgelistnetworkx.algorithms.node_classification.lgc.local_and_global_consistencynetworkx.algorithms.node_classification.hmn.harmonic_functionnetworkx.algorithms.bipartite.projection.generic_weighted_projected_graphnetworkx.algorithms.bipartite.projection.overlap_weighted_projected_graphnetworkx.classes.graph.Graph.remove_nodenetworkx.algorithms.tree.coding.from_prufer_sequencenetworkx.algorithms.assortativity.neighbor_degree.average_neighbor_degreenetworkx.classes.reportviews.OutEdgeView.datanetworkx.classes.multigraph.MultiGraphnetworkx.algorithms.operators.binary.intersectionnetworkx.algorithms.operators.binary.disjoint_unionnetworkx.algorithms.operators.binary.full_joinHover 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