Skip to content

Commit c879389

Browse files
authored
MAINT: Refactor graphviz figures to be lecture_specific figures.ipynb assets (#424)
* MAINT: refactor graphviz assets to lecture locations * update markov_chains_I * update markov_chain_II * update networks * clean up * manage merge conflict and ensure black edges
1 parent 079d9c1 commit c879389

26 files changed

+889
-565
lines changed

lectures/_static/lecture_specific/graphviz/graphviz_generation.ipynb

Lines changed: 0 additions & 565 deletions
This file was deleted.
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"id": "3c1ab515-e765-48f5-bfaf-35d4f95581fd",
6+
"metadata": {},
7+
"source": [
8+
"# Figures for Lake Model Lecture"
9+
]
10+
},
11+
{
12+
"cell_type": "code",
13+
"execution_count": 1,
14+
"id": "45727b3e-f531-4a31-b838-840ccf9d3c02",
15+
"metadata": {},
16+
"outputs": [
17+
{
18+
"name": "stdout",
19+
"output_type": "stream",
20+
"text": [
21+
"Requirement already satisfied: graphviz in /Users/mmcky/anaconda3/envs/quantecon/lib/python3.11/site-packages (0.20.3)\n"
22+
]
23+
}
24+
],
25+
"source": [
26+
"!pip install graphviz"
27+
]
28+
},
29+
{
30+
"cell_type": "code",
31+
"execution_count": 2,
32+
"id": "68e95ec8-877e-416a-a8ff-665715dfe222",
33+
"metadata": {},
34+
"outputs": [],
35+
"source": [
36+
"from graphviz import Digraph"
37+
]
38+
},
39+
{
40+
"cell_type": "code",
41+
"execution_count": 5,
42+
"id": "92a57207-4d79-4d7b-98c2-aea1a1e35f57",
43+
"metadata": {},
44+
"outputs": [
45+
{
46+
"data": {
47+
"text/plain": [
48+
"'lake_model_worker.png'"
49+
]
50+
},
51+
"execution_count": 5,
52+
"metadata": {},
53+
"output_type": "execute_result"
54+
}
55+
],
56+
"source": [
57+
"# Create Digraph object\n",
58+
"G = Digraph(format='png')\n",
59+
"G.attr(rankdir='LR')\n",
60+
"\n",
61+
"# Add nodes\n",
62+
"G.attr('node', shape='circle')\n",
63+
"G.node('1', 'New entrants', color='blue')\n",
64+
"G.node('2', 'Unemployed')\n",
65+
"G.node('3', 'Employed')\n",
66+
"\n",
67+
"# Add edges\n",
68+
"G.edge('1', '2', label='b')\n",
69+
"G.edge('2', '3', label='λ(1-d)')\n",
70+
"G.edge('3', '2', label='α(1-d)')\n",
71+
"G.edge('2', '2', label='(1-λ)(1-d)')\n",
72+
"G.edge('3', '3', label='(1-α)(1-d)')\n",
73+
"\n",
74+
"# Save Plot\n",
75+
"G.render(filename='lake_model_worker')"
76+
]
77+
},
78+
{
79+
"cell_type": "code",
80+
"execution_count": null,
81+
"id": "f6c2af58-4d38-44c3-adb0-d1a92a344e51",
82+
"metadata": {},
83+
"outputs": [],
84+
"source": []
85+
}
86+
],
87+
"metadata": {
88+
"kernelspec": {
89+
"display_name": "Python 3 (ipykernel)",
90+
"language": "python",
91+
"name": "python3"
92+
},
93+
"language_info": {
94+
"codemirror_mode": {
95+
"name": "ipython",
96+
"version": 3
97+
},
98+
"file_extension": ".py",
99+
"mimetype": "text/x-python",
100+
"name": "python",
101+
"nbconvert_exporter": "python",
102+
"pygments_lexer": "ipython3",
103+
"version": "3.11.7"
104+
}
105+
},
106+
"nbformat": 4,
107+
"nbformat_minor": 5
108+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
digraph {
2+
rankdir=LR
3+
node [shape=circle]
4+
1 [label="New entrants" color=blue]
5+
2 [label=Unemployed]
6+
3 [label=Employed]
7+
1 -> 2 [label=b]
8+
2 -> 3 [label="λ(1-d)"]
9+
3 -> 2 [label="α(1-d)"]
10+
2 -> 2 [label="(1-λ)(1-d)"]
11+
3 -> 3 [label="(1-α)(1-d)"]
12+
}
Loading
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
digraph {
2+
rankdir=LR
3+
ng
4+
mr
5+
sr
6+
ng -> ng [label=0.971]
7+
ng -> mr [label=0.029]
8+
mr -> ng [label=0.145]
9+
mr -> mr [label=0.778]
10+
mr -> sr [label=0.077]
11+
sr -> mr [label=0.508]
12+
sr -> sr [label=0.492]
13+
}
Loading
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
digraph {
2+
rankdir=LR
3+
Growth
4+
Stagnation
5+
Collapse
6+
Growth -> Growth [label=0.68]
7+
Growth -> Stagnation [label=0.12]
8+
Growth -> Collapse [label=0.20]
9+
Stagnation -> Stagnation [label=0.24]
10+
Stagnation -> Growth [label=0.50]
11+
Stagnation -> Collapse [label=0.26]
12+
Collapse -> Collapse [label=0.46]
13+
Collapse -> Stagnation [label=0.18]
14+
Collapse -> Growth [label=0.36]
15+
}
Loading
Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"id": "43b11347-069e-4c50-b093-4635361408fc",
6+
"metadata": {},
7+
"source": [
8+
"# Figures for Markov Chains I"
9+
]
10+
},
11+
{
12+
"cell_type": "code",
13+
"execution_count": 1,
14+
"id": "38b0e8a2-acab-4b27-95b3-96174c7d6863",
15+
"metadata": {},
16+
"outputs": [
17+
{
18+
"name": "stdout",
19+
"output_type": "stream",
20+
"text": [
21+
"Requirement already satisfied: graphviz in /Users/mmcky/anaconda3/envs/quantecon/lib/python3.11/site-packages (0.20.3)\n"
22+
]
23+
}
24+
],
25+
"source": [
26+
"!pip install graphviz"
27+
]
28+
},
29+
{
30+
"cell_type": "code",
31+
"execution_count": 2,
32+
"id": "606da6ac-e8b7-49c6-9d88-142e18e02bba",
33+
"metadata": {},
34+
"outputs": [],
35+
"source": [
36+
"from graphviz import Digraph"
37+
]
38+
},
39+
{
40+
"cell_type": "markdown",
41+
"id": "87430938-745b-45d3-9895-937bc357432d",
42+
"metadata": {},
43+
"source": [
44+
"## Example 1\n",
45+
"\n",
46+
"Hamilton on US unemployment data"
47+
]
48+
},
49+
{
50+
"cell_type": "code",
51+
"execution_count": 3,
52+
"id": "eff7a6b5-98d4-4f26-b72f-7100a911644e",
53+
"metadata": {},
54+
"outputs": [
55+
{
56+
"data": {
57+
"text/plain": [
58+
"'Hamilton.png'"
59+
]
60+
},
61+
"execution_count": 3,
62+
"metadata": {},
63+
"output_type": "execute_result"
64+
}
65+
],
66+
"source": [
67+
"dot = Digraph(format='png')\n",
68+
"dot.attr(rankdir='LR')\n",
69+
"dot.node(\"ng\")\n",
70+
"dot.node(\"mr\")\n",
71+
"dot.node(\"sr\")\n",
72+
"\n",
73+
"dot.edge(\"ng\", \"ng\", label=\"0.971\")\n",
74+
"dot.edge(\"ng\", \"mr\", label=\"0.029\")\n",
75+
"dot.edge(\"mr\", \"ng\", label=\"0.145\")\n",
76+
"\n",
77+
"dot.edge(\"mr\", \"mr\", label=\"0.778\")\n",
78+
"dot.edge(\"mr\", \"sr\", label=\"0.077\")\n",
79+
"dot.edge(\"sr\", \"mr\", label=\"0.508\")\n",
80+
"\n",
81+
"dot.edge(\"sr\", \"sr\", label=\"0.492\")\n",
82+
"dot\n",
83+
"\n",
84+
"dot.render(filename='Hamilton')"
85+
]
86+
},
87+
{
88+
"cell_type": "markdown",
89+
"id": "7effdaa6-ee97-4634-811c-1b90d7e95543",
90+
"metadata": {},
91+
"source": [
92+
"## Exercise 1\n",
93+
"\n",
94+
"Solution 2:"
95+
]
96+
},
97+
{
98+
"cell_type": "code",
99+
"execution_count": 4,
100+
"id": "bb57212a-c0f2-4922-a549-0edea60ec590",
101+
"metadata": {},
102+
"outputs": [
103+
{
104+
"data": {
105+
"text/plain": [
106+
"'Temple.png'"
107+
]
108+
},
109+
"execution_count": 4,
110+
"metadata": {},
111+
"output_type": "execute_result"
112+
}
113+
],
114+
"source": [
115+
"dot = Digraph(format='png')\n",
116+
"dot.attr(rankdir='LR')\n",
117+
"dot.node(\"Growth\")\n",
118+
"dot.node(\"Stagnation\")\n",
119+
"dot.node(\"Collapse\")\n",
120+
"\n",
121+
"dot.edge(\"Growth\", \"Growth\", label=\"0.68\")\n",
122+
"dot.edge(\"Growth\", \"Stagnation\", label=\"0.12\")\n",
123+
"dot.edge(\"Growth\", \"Collapse\", label=\"0.20\")\n",
124+
"\n",
125+
"dot.edge(\"Stagnation\", \"Stagnation\", label=\"0.24\")\n",
126+
"dot.edge(\"Stagnation\", \"Growth\", label=\"0.50\")\n",
127+
"dot.edge(\"Stagnation\", \"Collapse\", label=\"0.26\")\n",
128+
"\n",
129+
"dot.edge(\"Collapse\", \"Collapse\", label=\"0.46\")\n",
130+
"dot.edge(\"Collapse\", \"Stagnation\", label=\"0.18\")\n",
131+
"dot.edge(\"Collapse\", \"Growth\", label=\"0.36\")\n",
132+
"\n",
133+
"dot\n",
134+
"\n",
135+
"dot.render(filename='Temple')"
136+
]
137+
},
138+
{
139+
"cell_type": "code",
140+
"execution_count": null,
141+
"id": "7aca758c-e819-4d01-a2aa-c5fd36f0e2ad",
142+
"metadata": {},
143+
"outputs": [],
144+
"source": []
145+
}
146+
],
147+
"metadata": {
148+
"kernelspec": {
149+
"display_name": "Python 3 (ipykernel)",
150+
"language": "python",
151+
"name": "python3"
152+
},
153+
"language_info": {
154+
"codemirror_mode": {
155+
"name": "ipython",
156+
"version": 3
157+
},
158+
"file_extension": ".py",
159+
"mimetype": "text/x-python",
160+
"name": "python",
161+
"nbconvert_exporter": "python",
162+
"pygments_lexer": "ipython3",
163+
"version": "3.11.7"
164+
}
165+
},
166+
"nbformat": 4,
167+
"nbformat_minor": 5
168+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
digraph {
2+
rankdir=LR
3+
poor
4+
"middle class"
5+
rich
6+
poor -> poor [label=0.9]
7+
poor -> "middle class" [label=0.1]
8+
"middle class" -> poor [label=0.4]
9+
"middle class" -> "middle class" [label=0.4]
10+
"middle class" -> rich [label=0.2]
11+
rich -> poor [label=0.1]
12+
rich -> "middle class" [label=0.1]
13+
rich -> rich [label=0.8]
14+
}
Loading
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
digraph {
2+
rankdir=LR
3+
poor
4+
"middle class"
5+
rich
6+
poor -> poor [label=1.0]
7+
"middle class" -> poor [label=0.1]
8+
"middle class" -> "middle class" [label=0.8]
9+
"middle class" -> rich [label=0.1]
10+
rich -> "middle class" [label=0.2]
11+
rich -> rich [label=0.8]
12+
}
Loading
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
digraph {
2+
rankdir=LR
3+
0
4+
1
5+
0 -> 1 [label=1.0]
6+
1 -> 0 [label=1.0]
7+
}

0 commit comments

Comments
 (0)