Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 56 additions & 2 deletions docs/tutorials/intro_tutorial.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1059,6 +1059,60 @@
"g.set(title=\"Wealth of agent 14 over time\");"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"You can also plot a reporter of multiple agents over time."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"agent_list = [3, 14, 25]\n",
"\n",
"# Get the wealth of multiple agents over time\n",
"multiple_agents_wealth = agent_wealth[\n",
" agent_wealth.index.get_level_values(\"AgentID\").isin(agent_list)\n",
"]\n",
"# Plot the wealth of multiple agents over time\n",
"g = sns.lineplot(data=multiple_agents_wealth, x=\"Step\", y=\"Wealth\", hue=\"AgentID\")\n",
"g.set(title=\"Wealth of agents 3, 14 and 25 over time\");"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can also plot the average of all agents, with a 95% confidence interval for that average."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Transform the data to a long format\n",
"agent_wealth_long = agent_wealth.T.unstack().reset_index()\n",
"agent_wealth_long.columns = [\"Step\", \"AgentID\", \"Variable\", \"Value\"]\n",
"agent_wealth_long.head(3)\n",
"\n",
"# Plot the average wealth over time\n",
"g = sns.lineplot(data=agent_wealth_long, x=\"Step\", y=\"Value\", errorbar=(\"ci\", 95))\n",
"g.set(title=\"Average wealth over time\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Which is exactly 1, as expected in this model, since each agent starts with one wealth unit, and each agent gives one wealth unit to another agent at each step."
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -1369,7 +1423,7 @@
"metadata": {
"anaconda-cloud": {},
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -1383,7 +1437,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.6"
"version": "3.10.12"
},
"widgets": {
"state": {},
Expand Down