From ba6d2d51652ed7d64658d0389de895adef1f363f Mon Sep 17 00:00:00 2001 From: corvince <13568919+Corvince@users.noreply.github.com> Date: Wed, 16 Oct 2024 21:11:35 +0200 Subject: [PATCH] add a note and fix histogram code --- docs/tutorials/visualization_tutorial.ipynb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/tutorials/visualization_tutorial.ipynb b/docs/tutorials/visualization_tutorial.ipynb index b536752fba6..03c594bc4d3 100644 --- a/docs/tutorials/visualization_tutorial.ipynb +++ b/docs/tutorials/visualization_tutorial.ipynb @@ -194,7 +194,9 @@ "\n", "If the visualization elements provided by Mesa aren't enough for you, you can build your own and plug them into the model server.\n", "\n", - "For this example, let's build a simple histogram visualization, which can count the number of agents with each value of wealth." + "For this example, let's build a simple histogram visualization, which can count the number of agents with each value of wealth.\n", + "\n", + "**Note:** Due to the way solara works we need to trigger an update whenever the underlying model changes. For this you need to register an update counter with every component." ] }, { @@ -205,9 +207,11 @@ "source": [ "import solara\n", "from matplotlib.figure import Figure\n", + "from mesa.visualization.utils import update_counter\n", "\n", "@solara.component\n", "def Histogram(model):\n", + " update_counter.get() # This is required to update the counter\n", " # Note: you must initialize a figure using this method instead of\n", " # plt.figure(), for thread safety purpose\n", " fig = Figure()\n",