Skip to content

Commit 21ac431

Browse files
rhtjackiekazil
authored andcommitted
JupyterViz: Convert make_plot to Solara component
1 parent d6821a4 commit 21ac431

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

mesa/experimental/components/matplotlib.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ def portray(space):
112112
space_ax.scatter(**portray(space))
113113

114114

115-
def make_plot(model, measure):
115+
@solara.component
116+
def PlotMatplotlib(model, measure, dependencies: Optional[list[any]] = None):
116117
fig = Figure()
117118
ax = fig.subplots()
118119
df = model.datacollector.get_model_vars_dataframe()
@@ -129,4 +130,4 @@ def make_plot(model, measure):
129130
fig.legend()
130131
# Set integer x axis
131132
ax.xaxis.set_major_locator(MaxNLocator(integer=True))
132-
solara.FigureMatplotlib(fig)
133+
solara.FigureMatplotlib(fig, dependencies=dependencies)

mesa/experimental/jupyter_viz.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ def Card(
3737
# Is a custom object
3838
measure(model)
3939
else:
40-
components_matplotlib.make_plot(model, measure)
40+
components_matplotlib.PlotMatplotlib(
41+
model, measure, dependencies=[current_step.value]
42+
)
4143
return main
4244

4345

@@ -116,13 +118,14 @@ def render_in_jupyter():
116118
# otherwise, do nothing (do not draw space)
117119

118120
# 5. Plots
119-
120121
for measure in measures:
121122
if callable(measure):
122123
# Is a custom object
123124
measure(model)
124125
else:
125-
components_matplotlib.make_plot(model, measure)
126+
components_matplotlib.PlotMatplotlib(
127+
model, measure, dependencies=[current_step.value]
128+
)
126129

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

0 commit comments

Comments
 (0)