Skip to content

Commit

Permalink
add a note and fix histogram code
Browse files Browse the repository at this point in the history
  • Loading branch information
Corvince committed Oct 16, 2024
1 parent 9baee14 commit ba6d2d5
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion docs/tutorials/visualization_tutorial.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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."
]
},
{
Expand All @@ -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",
Expand Down

0 comments on commit ba6d2d5

Please sign in to comment.