Fixed database typo and removed unnecessary class identifier.
This commit is contained in:
parent
00ad49a143
commit
45fb349a7d
5098 changed files with 952558 additions and 85 deletions
|
@ -0,0 +1,2 @@
|
|||
Pygraphviz
|
||||
----------
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,38 @@
|
|||
"""
|
||||
=====================
|
||||
Pygraphviz Attributes
|
||||
=====================
|
||||
|
||||
An example showing how to use the interface to the pygraphviz
|
||||
AGraph class to convert to and from graphviz.
|
||||
|
||||
Also see the pygraphviz documentation and examples at
|
||||
http://pygraphviz.github.io/
|
||||
"""
|
||||
|
||||
import networkx as nx
|
||||
|
||||
# networkx graph
|
||||
G = nx.Graph()
|
||||
# ad edges with red color
|
||||
G.add_edge(1, 2, color="red")
|
||||
G.add_edge(2, 3, color="red")
|
||||
# add nodes 3 and 4
|
||||
G.add_node(3)
|
||||
G.add_node(4)
|
||||
|
||||
# convert to a graphviz agraph
|
||||
A = nx.nx_agraph.to_agraph(G)
|
||||
|
||||
# write to dot file
|
||||
A.write("k5_attributes.dot")
|
||||
|
||||
# convert back to networkx Graph with attributes on edges and
|
||||
# default attributes as dictionary data
|
||||
X = nx.nx_agraph.from_agraph(A)
|
||||
print("edges")
|
||||
print(list(X.edges(data=True)))
|
||||
print("default graph attributes")
|
||||
print(X.graph)
|
||||
print("node node attributes")
|
||||
print(X.nodes.data(True))
|
|
@ -0,0 +1,19 @@
|
|||
"""
|
||||
===============
|
||||
Pygraphviz Draw
|
||||
===============
|
||||
|
||||
An example showing how to use the interface to the pygraphviz
|
||||
AGraph class to draw a graph.
|
||||
|
||||
Also see the pygraphviz documentation and examples at
|
||||
http://pygraphviz.github.io/
|
||||
"""
|
||||
|
||||
import networkx as nx
|
||||
|
||||
# plain graph
|
||||
G = nx.complete_graph(5) # start with K5 in networkx
|
||||
A = nx.nx_agraph.to_agraph(G) # convert to a graphviz graph
|
||||
A.layout() # neato layout
|
||||
A.draw("k5.ps") # write postscript in k5.ps with neato layout
|
|
@ -0,0 +1,23 @@
|
|||
"""
|
||||
=================
|
||||
Pygraphviz Simple
|
||||
=================
|
||||
|
||||
An example showing how to use the interface to the pygraphviz
|
||||
AGraph class to convert to and from graphviz.
|
||||
|
||||
Also see the pygraphviz documentation and examples at
|
||||
http://pygraphviz.github.io/
|
||||
"""
|
||||
|
||||
import networkx as nx
|
||||
|
||||
# plain graph
|
||||
G = nx.complete_graph(5) # start with K5 in networkx
|
||||
A = nx.nx_agraph.to_agraph(G) # convert to a graphviz graph
|
||||
X1 = nx.nx_agraph.from_agraph(A) # convert back to networkx (but as Graph)
|
||||
X2 = nx.Graph(A) # fancy way to do conversion
|
||||
G1 = nx.Graph(X1) # now make it a Graph
|
||||
|
||||
A.write("k5.dot") # write to dot file
|
||||
X3 = nx.nx_agraph.read_dot("k5.dot") # read from dotfile
|
|
@ -0,0 +1,23 @@
|
|||
"""
|
||||
=============
|
||||
Write Dotfile
|
||||
=============
|
||||
|
||||
|
||||
Write a dot file from a networkx graph for further processing with graphviz.
|
||||
|
||||
You need to have either pygraphviz or pydot for this example.
|
||||
|
||||
See https://networkx.github.io/documentation/latest/reference/drawing.html
|
||||
"""
|
||||
|
||||
import networkx as nx
|
||||
|
||||
# This example needs Graphviz and either PyGraphviz or pydot.
|
||||
# from networkx.drawing.nx_pydot import write_dot
|
||||
from networkx.drawing.nx_agraph import write_dot
|
||||
|
||||
|
||||
G = nx.grid_2d_graph(5, 5) # 5x5 grid
|
||||
write_dot(G, "grid.dot")
|
||||
print("Now run: neato -Tps grid.dot >grid.ps")
|
Loading…
Add table
Add a link
Reference in a new issue