Skip to content

Commit 9ebb9b0

Browse files
committed
Add 1.11 docs
1 parent 0a288a7 commit 9ebb9b0

File tree

141 files changed

+15167
-13802
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

141 files changed

+15167
-13802
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"\n# Subgraph\n\nSpecify a subgraph in pygraphviz.\n"
8+
]
9+
},
10+
{
11+
"cell_type": "code",
12+
"execution_count": null,
13+
"metadata": {
14+
"collapsed": false
15+
},
16+
"outputs": [],
17+
"source": [
18+
"import pygraphviz as pgv\n\nA = pgv.AGraph()\n# add some edges\nA.add_edge(1, 2)\nA.add_edge(2, 3)\nA.add_edge(1, 3)\nA.add_edge(3, 4)\nA.add_edge(3, 5)\nA.add_edge(3, 6)\nA.add_edge(4, 6)\n# make a subgraph with rank='same'\nB = A.add_subgraph([4, 5, 6], name=\"s1\", rank=\"same\")\nB.graph_attr[\"rank\"] = \"same\"\nprint(A.string()) # print dot file to standard output\nA.draw(\"subgraph.png\", prog=\"neato\")"
19+
]
20+
}
21+
],
22+
"metadata": {
23+
"kernelspec": {
24+
"display_name": "Python 3",
25+
"language": "python",
26+
"name": "python3"
27+
},
28+
"language_info": {
29+
"codemirror_mode": {
30+
"name": "ipython",
31+
"version": 3
32+
},
33+
"file_extension": ".py",
34+
"mimetype": "text/x-python",
35+
"name": "python",
36+
"nbconvert_exporter": "python",
37+
"pygments_lexer": "ipython3",
38+
"version": "3.10.11"
39+
}
40+
},
41+
"nbformat": 4,
42+
"nbformat_minor": 0
43+
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
"""
2+
Knuth Miles
3+
===========
4+
5+
An example that shows how to add your own positions to nodes
6+
and have graphviz "neato" position the edges.
7+
8+
miles_graph() returns an undirected graph over the 128 US cities from
9+
the datafile miles_dat.txt.
10+
11+
This example is described in Section 1.1 in Knuth's book [1]_ [2]_.
12+
13+
The data used in this example is copied from [2]_. The filename and
14+
header have been modified to adhere to the request of the author to
15+
not corrupt the original source file content and name.
16+
17+
References.
18+
-----------
19+
.. [1] Donald E. Knuth,
20+
"The Stanford GraphBase: A Platform for Combinatorial Computing",
21+
ACM Press, New York, 1993.
22+
.. [2] http://www-cs-faculty.stanford.edu/~knuth/sgb.html
23+
"""
24+
25+
__author__ = """Aric Hagberg (aric.hagberg@gmail.com)"""
26+
27+
28+
def miles_graph():
29+
"""Return a graph from the data in miles_dat.txt.
30+
31+
Edges are made between cities that are less then 300 miles apart.
32+
"""
33+
import math
34+
import re
35+
import gzip
36+
37+
G = pgv.AGraph(name="miles_dat")
38+
G.node_attr["shape"] = "circle"
39+
G.node_attr["fixedsize"] = "true"
40+
G.node_attr["fontsize"] = "8"
41+
G.node_attr["style"] = "filled"
42+
G.graph_attr["outputorder"] = "edgesfirst"
43+
G.graph_attr["label"] = "miles_dat"
44+
G.graph_attr["ratio"] = "1.0"
45+
G.edge_attr["color"] = "#1100FF"
46+
G.edge_attr["style"] = "setlinewidth(2)"
47+
48+
cities = []
49+
for line in gzip.open("miles_dat.txt.gz", "rt"):
50+
if line.startswith("*"): # skip comments
51+
continue
52+
numfind = re.compile(r"^\d+")
53+
54+
if numfind.match(line): # this line is distances
55+
dist = line.split()
56+
for d in dist:
57+
if float(d) < 300: # connect if closer then 300 miles
58+
G.add_edge(city, cities[i])
59+
i = i + 1
60+
else: # this line is a city, position, population
61+
i = 1
62+
(city, coordpop) = line.split("[")
63+
cities.insert(0, city)
64+
(coord, pop) = coordpop.split("]")
65+
(y, x) = coord.split(",")
66+
G.add_node(city)
67+
n = G.get_node(city)
68+
# assign positions, scale to be something reasonable in points
69+
n.attr[
70+
"pos"
71+
] = f"{-(float(x) - 7000) / 10.0:f},{(float(y) - 2000) / 10.0:f}"
72+
# assign node size, in sqrt of 1,000,000's of people
73+
d = math.sqrt(float(pop) / 1000000.0)
74+
n.attr["height"] = f"{d / 2}"
75+
n.attr["width"] = f"{d / 2}"
76+
# assign node color
77+
n.attr["fillcolor"] = f"#0000{int(d * 256):2x}"
78+
# empty labels
79+
n.attr["label"] = " "
80+
81+
return G
82+
83+
84+
if __name__ == "__main__":
85+
import warnings
86+
import pygraphviz as pgv
87+
88+
# ignore Graphviz warning messages
89+
warnings.simplefilter("ignore", RuntimeWarning)
90+
91+
G = miles_graph()
92+
print("Loaded miles_dat.txt containing 128 cities.")
93+
94+
G.write("miles.dot")
95+
print("Wrote miles.dot")
96+
G.draw("miles.png", prog="neato", args="-n2")
97+
print("Wrote miles.png")
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
"""
2+
Star
3+
====
4+
5+
Create and draw a star with varying node properties.
6+
"""
7+
# Copyright (C) 2006 by
8+
# Aric Hagberg <hagberg@lanl.gov>
9+
# Dan Schult <dschult@colgate.edu>
10+
# Manos Renieris, http://www.cs.brown.edu/~er/
11+
# Distributed with BSD license.
12+
# All rights reserved, see LICENSE for details.
13+
14+
15+
__author__ = """Aric Hagberg (hagberg@lanl.gov)"""
16+
17+
from pygraphviz import *
18+
19+
A = AGraph()
20+
21+
# set some default node attributes
22+
A.node_attr["style"] = "filled"
23+
A.node_attr["shape"] = "circle"
24+
A.node_attr["fixedsize"] = "true"
25+
A.node_attr["fontcolor"] = "#FFFFFF"
26+
27+
# make a star in shades of red
28+
for i in range(1, 16):
29+
A.add_edge(0, i)
30+
n = A.get_node(i)
31+
n.attr["fillcolor"] = f"#{i * 16:2x}0000"
32+
n.attr["height"] = f"{i / 16.0 + 0.5}"
33+
n.attr["width"] = f"{i / 16.0 + 0.5}"
34+
35+
print(A.string()) # print to screen
36+
A.write("star.dot") # write to simple.dot
37+
A.draw("star.png", prog="circo") # draw to png using circo layout
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"\n# Star\n\nCreate and draw a star with varying node properties.\n"
8+
]
9+
},
10+
{
11+
"cell_type": "code",
12+
"execution_count": null,
13+
"metadata": {
14+
"collapsed": false
15+
},
16+
"outputs": [],
17+
"source": [
18+
"# Copyright (C) 2006 by\n# Aric Hagberg <hagberg@lanl.gov>\n# Dan Schult <dschult@colgate.edu>\n# Manos Renieris, http://www.cs.brown.edu/~er/\n# Distributed with BSD license.\n# All rights reserved, see LICENSE for details.\n\n\n__author__ = \"\"\"Aric Hagberg (hagberg@lanl.gov)\"\"\"\n\nfrom pygraphviz import *\n\nA = AGraph()\n\n# set some default node attributes\nA.node_attr[\"style\"] = \"filled\"\nA.node_attr[\"shape\"] = \"circle\"\nA.node_attr[\"fixedsize\"] = \"true\"\nA.node_attr[\"fontcolor\"] = \"#FFFFFF\"\n\n# make a star in shades of red\nfor i in range(1, 16):\n A.add_edge(0, i)\n n = A.get_node(i)\n n.attr[\"fillcolor\"] = f\"#{i * 16:2x}0000\"\n n.attr[\"height\"] = f\"{i / 16.0 + 0.5}\"\n n.attr[\"width\"] = f\"{i / 16.0 + 0.5}\"\n\nprint(A.string()) # print to screen\nA.write(\"star.dot\") # write to simple.dot\nA.draw(\"star.png\", prog=\"circo\") # draw to png using circo layout"
19+
]
20+
}
21+
],
22+
"metadata": {
23+
"kernelspec": {
24+
"display_name": "Python 3",
25+
"language": "python",
26+
"name": "python3"
27+
},
28+
"language_info": {
29+
"codemirror_mode": {
30+
"name": "ipython",
31+
"version": 3
32+
},
33+
"file_extension": ".py",
34+
"mimetype": "text/x-python",
35+
"name": "python",
36+
"nbconvert_exporter": "python",
37+
"pygments_lexer": "ipython3",
38+
"version": "3.10.11"
39+
}
40+
},
41+
"nbformat": 4,
42+
"nbformat_minor": 0
43+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"\n# Basic\n\nA simple example to create a graphviz dot file and draw a graph.\n"
8+
]
9+
},
10+
{
11+
"cell_type": "code",
12+
"execution_count": null,
13+
"metadata": {
14+
"collapsed": false
15+
},
16+
"outputs": [],
17+
"source": [
18+
"# Copyright (C) 2006 by\n# Aric Hagberg <hagberg@lanl.gov>\n# Dan Schult <dschult@colgate.edu>\n# Manos Renieris, http://www.cs.brown.edu/~er/\n# Distributed with BSD license.\n# All rights reserved, see LICENSE for details.\n\n\n__author__ = \"\"\"Aric Hagberg (hagberg@lanl.gov)\"\"\"\n\nimport pygraphviz as pgv\n\nA = pgv.AGraph()\n\nA.add_edge(1, 2)\nA.add_edge(2, 3)\nA.add_edge(1, 3)\n\nprint(A.string()) # print to screen\nA.write(\"simple.dot\") # write to simple.dot\n\nB = pgv.AGraph(\"simple.dot\") # create a new graph from file\nB.layout() # layout with default (neato)\nB.draw(\"simple.png\") # draw png"
19+
]
20+
}
21+
],
22+
"metadata": {
23+
"kernelspec": {
24+
"display_name": "Python 3",
25+
"language": "python",
26+
"name": "python3"
27+
},
28+
"language_info": {
29+
"codemirror_mode": {
30+
"name": "ipython",
31+
"version": 3
32+
},
33+
"file_extension": ".py",
34+
"mimetype": "text/x-python",
35+
"name": "python",
36+
"nbconvert_exporter": "python",
37+
"pygments_lexer": "ipython3",
38+
"version": "3.10.11"
39+
}
40+
},
41+
"nbformat": 4,
42+
"nbformat_minor": 0
43+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"\n# Attributes\n\nExample illustrating how to set node, edge, and graph attributes for\nvisualization.\n"
8+
]
9+
},
10+
{
11+
"cell_type": "code",
12+
"execution_count": null,
13+
"metadata": {
14+
"collapsed": false
15+
},
16+
"outputs": [],
17+
"source": [
18+
"import pygraphviz as pgv\n\n# strict (no parallel edges)\n# digraph\n# with attribute rankdir set to 'LR'\nA = pgv.AGraph(directed=True, strict=True, rankdir=\"LR\")\n# add node 1 with color red\nA.add_node(1, color=\"red\")\nA.add_node(5, color=\"blue\")\n# add some edges\nA.add_edge(1, 2, color=\"green\")\nA.add_edge(2, 3)\nA.add_edge(1, 3)\nA.add_edge(3, 4)\nA.add_edge(3, 5)\nA.add_edge(3, 6)\nA.add_edge(4, 6)\n# adjust a graph parameter\nA.graph_attr[\"epsilon\"] = \"0.001\"\nprint(A.string()) # print dot file to standard output\nA.layout(\"dot\") # layout with dot\nA.draw(\"foo.png\") # write to file"
19+
]
20+
}
21+
],
22+
"metadata": {
23+
"kernelspec": {
24+
"display_name": "Python 3",
25+
"language": "python",
26+
"name": "python3"
27+
},
28+
"language_info": {
29+
"codemirror_mode": {
30+
"name": "ipython",
31+
"version": 3
32+
},
33+
"file_extension": ".py",
34+
"mimetype": "text/x-python",
35+
"name": "python",
36+
"nbconvert_exporter": "python",
37+
"pygments_lexer": "ipython3",
38+
"version": "3.10.11"
39+
}
40+
},
41+
"nbformat": 4,
42+
"nbformat_minor": 0
43+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"""
2+
Attributes
3+
----------
4+
5+
Example illustrating how to set node, edge, and graph attributes for
6+
visualization.
7+
"""
8+
9+
import pygraphviz as pgv
10+
11+
# strict (no parallel edges)
12+
# digraph
13+
# with attribute rankdir set to 'LR'
14+
A = pgv.AGraph(directed=True, strict=True, rankdir="LR")
15+
# add node 1 with color red
16+
A.add_node(1, color="red")
17+
A.add_node(5, color="blue")
18+
# add some edges
19+
A.add_edge(1, 2, color="green")
20+
A.add_edge(2, 3)
21+
A.add_edge(1, 3)
22+
A.add_edge(3, 4)
23+
A.add_edge(3, 5)
24+
A.add_edge(3, 6)
25+
A.add_edge(4, 6)
26+
# adjust a graph parameter
27+
A.graph_attr["epsilon"] = "0.001"
28+
print(A.string()) # print dot file to standard output
29+
A.layout("dot") # layout with dot
30+
A.draw("foo.png") # write to file
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"""
2+
Subgraph
3+
========
4+
5+
Specify a subgraph in pygraphviz.
6+
"""
7+
8+
import pygraphviz as pgv
9+
10+
A = pgv.AGraph()
11+
# add some edges
12+
A.add_edge(1, 2)
13+
A.add_edge(2, 3)
14+
A.add_edge(1, 3)
15+
A.add_edge(3, 4)
16+
A.add_edge(3, 5)
17+
A.add_edge(3, 6)
18+
A.add_edge(4, 6)
19+
# make a subgraph with rank='same'
20+
B = A.add_subgraph([4, 5, 6], name="s1", rank="same")
21+
B.graph_attr["rank"] = "same"
22+
print(A.string()) # print dot file to standard output
23+
A.draw("subgraph.png", prog="neato")

0 commit comments

Comments
 (0)