to_directed(self, as_view=False)
This returns a "deepcopy" of the edge, node, and graph attributes which attempts to completely copy all of the data and references.
This is in contrast to the similar D=DiGraph(G) which returns a shallow copy of the data.
See the Python copy module for more information on shallow and deep copies, https://docs.python.org/3/library/copy.html.
Warning: If you have subclassed Graph to use dict-like objects in the data structure, those changes do not transfer to the DiGraph created by this method.
A directed graph with the same name, same nodes, and with each edge (u, v, data) replaced by two directed edges (u, v, data) and (v, u, data).
Returns a directed representation of the graph.
>>> G = nx.Graph() # or MultiGraph, etc
... G.add_edge(0, 1)
... H = G.to_directed()
... list(H.edges) [(0, 1), (1, 0)]
If already directed, return a (deep) copy
>>> G = nx.DiGraph() # or MultiDiGraph, etcSee :
... G.add_edge(0, 1)
... H = G.to_directed()
... list(H.edges) [(0, 1)]
The following pages refer to to this document either explicitly or contain code examples using this.
networkx.classes.graph.Graph.copy
networkx.classes.graph.Graph.to_undirected
networkx.classes.multidigraph.MultiDiGraph.to_undirected
networkx.classes.digraph.DiGraph.to_undirected
networkx.classes.graph.Graph.to_directed
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