Skip to content

Commit

Permalink
Jupyter_viz: Allow measures to be None (#2163)
Browse files Browse the repository at this point in the history
Currently measures crashed when it's None (which is the default). The only way to circumvent this is adding [], but that's non-ideal and not obvious.

This PR fixes that, so that measures can actually be the default value of None.

This also proves we need to test Jupyter viz in notebooks, not only in console, since both have different code paths.
  • Loading branch information
EwoutH authored Jul 3, 2024
1 parent 4cc0c82 commit 0868f4b
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions mesa/visualization/jupyter_viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,15 @@ def render_in_jupyter():
# otherwise, do nothing (do not draw space)

# 5. Plots
for measure in measures:
if callable(measure):
# Is a custom object
measure(model)
else:
components_matplotlib.PlotMatplotlib(
model, measure, dependencies=dependencies
)
if measures:
for measure in measures:
if callable(measure):
# Is a custom object
measure(model)
else:
components_matplotlib.PlotMatplotlib(
model, measure, dependencies=dependencies
)

def render_in_browser():
# if space drawer is disabled, do not include it
Expand Down

0 comments on commit 0868f4b

Please sign in to comment.