Skip to content

Commit 275fc70

Browse files
committed
update code to generate graphviz plots
1 parent 1a1e771 commit 275fc70

File tree

1 file changed

+121
-0
lines changed

1 file changed

+121
-0
lines changed
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"id": "ccd1c797-db85-4293-8436-0cd442d1d9ae",
6+
"metadata": {},
7+
"source": [
8+
"# Code for Graphviz Plots "
9+
]
10+
},
11+
{
12+
"cell_type": "code",
13+
"execution_count": 1,
14+
"id": "6f6a377d-1fc8-4f2a-8e92-b550a7c92828",
15+
"metadata": {},
16+
"outputs": [
17+
{
18+
"name": "stdout",
19+
"output_type": "stream",
20+
"text": [
21+
"Requirement already satisfied: graphviz in /Users/humphreyyang/anaconda3/envs/quantecon/lib/python3.9/site-packages (0.20.1)\n"
22+
]
23+
}
24+
],
25+
"source": [
26+
"!pip install graphviz"
27+
]
28+
},
29+
{
30+
"cell_type": "markdown",
31+
"id": "ad403a5a-868c-45ed-a360-a81aee9cfd38",
32+
"metadata": {},
33+
"source": [
34+
"```{admonition} graphviz\n",
35+
":class: warning\n",
36+
"If you are running this lecture locally it requires [graphviz](https://www.graphviz.org)\n",
37+
"to be installed on your computer. Installation instructions for graphviz can be found\n",
38+
"[here](https://www.graphviz.org/download/) \n",
39+
"```"
40+
]
41+
},
42+
{
43+
"cell_type": "code",
44+
"execution_count": 2,
45+
"id": "428161a2-e0d5-402e-bf16-1d1e460a30e7",
46+
"metadata": {},
47+
"outputs": [],
48+
"source": [
49+
"from graphviz import Digraph\n"
50+
]
51+
},
52+
{
53+
"cell_type": "markdown",
54+
"id": "75d07327-0fcc-41f1-8d36-b8b8d4eb1060",
55+
"metadata": {},
56+
"source": [
57+
"## Lake Model"
58+
]
59+
},
60+
{
61+
"cell_type": "code",
62+
"execution_count": 12,
63+
"id": "16e9379d-bf94-4c79-9a34-4dbc2cc41b0e",
64+
"metadata": {},
65+
"outputs": [
66+
{
67+
"data": {
68+
"text/plain": [
69+
"'../lake_model/lake_model_worker.png'"
70+
]
71+
},
72+
"execution_count": 12,
73+
"metadata": {},
74+
"output_type": "execute_result"
75+
}
76+
],
77+
"source": [
78+
"# Create Digraph object\n",
79+
"G = Digraph(format='png')\n",
80+
"G.attr(rankdir='LR')\n",
81+
"\n",
82+
"# Add nodes\n",
83+
"G.attr('node', shape='circle')\n",
84+
"G.node('1', 'New entrants', color='blue')\n",
85+
"G.node('2', 'Unemployed')\n",
86+
"G.node('3', 'Employed')\n",
87+
"\n",
88+
"# Add edges\n",
89+
"G.edge('1', '2', label='b')\n",
90+
"G.edge('2', '3', label='λ(1-d)')\n",
91+
"G.edge('3', '2', label='α(1-d)')\n",
92+
"G.edge('2', '2', label='(1-λ)(1-d)')\n",
93+
"G.edge('3', '3', label='(1-α)(1-d)')\n",
94+
"\n",
95+
"# Show graphviz\n",
96+
"G.render(filename='../lake_model/lake_model_worker')"
97+
]
98+
}
99+
],
100+
"metadata": {
101+
"kernelspec": {
102+
"display_name": "Python 3 (ipykernel)",
103+
"language": "python",
104+
"name": "python3"
105+
},
106+
"language_info": {
107+
"codemirror_mode": {
108+
"name": "ipython",
109+
"version": 3
110+
},
111+
"file_extension": ".py",
112+
"mimetype": "text/x-python",
113+
"name": "python",
114+
"nbconvert_exporter": "python",
115+
"pygments_lexer": "ipython3",
116+
"version": "3.9.16"
117+
}
118+
},
119+
"nbformat": 4,
120+
"nbformat_minor": 5
121+
}

0 commit comments

Comments
 (0)