diff --git a/docs/tutorials/intro_tutorial.ipynb b/docs/tutorials/intro_tutorial.ipynb index 404ae8d25bf..1aa8d4d1c4b 100644 --- a/docs/tutorials/intro_tutorial.ipynb +++ b/docs/tutorials/intro_tutorial.ipynb @@ -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": {}, @@ -1369,7 +1423,7 @@ "metadata": { "anaconda-cloud": {}, "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -1383,7 +1437,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.6" + "version": "3.10.12" }, "widgets": { "state": {},