diff --git a/mesa/experimental/jupyter_viz.py b/mesa/experimental/jupyter_viz.py index 0ecd4e8b024..099e363193f 100644 --- a/mesa/experimental/jupyter_viz.py +++ b/mesa/experimental/jupyter_viz.py @@ -8,10 +8,12 @@ from matplotlib.ticker import MaxNLocator from solara.components.columns import Columns +# from matplotlib.pyplot import figure import mesa # Avoid interactive backend plt.switch_backend("agg") +plt.rcParams["figure.figsize"] = (7, 7) @solara.component @@ -53,6 +55,9 @@ def make_model(): return model def calculate_space_size(): + if model_parameters["N"] > 50: + fixed_size = int(model_parameters["N"] / 10) + plt.rcParams["figure.figsize"] = (fixed_size, fixed_size) pass def calculate_agent_size(): @@ -78,7 +83,8 @@ def handle_change_model_params(name: str, value: any): with solara.AppBarTitle(): solara.Text(name) # calculate agent size based on number of users - agent_size_delta = calculate_agent_size() + # agent_size_delta = calculate_agent_size() + calculate_space_size() with solara.Sidebar(): with solara.Card("Controls", margin=1, elevation=2): @@ -90,11 +96,11 @@ def handle_change_model_params(name: str, value: any): # solara.ProgressLinear(True) solara.Markdown(md_text=f"####Step - {current_step}") - with Columns(widths=[4, 4]): + with solara.Row(): # 4. Space if space_drawer == "default": # draw with the default implementation - make_space(model, agent_portrayal, delta=agent_size_delta) + make_space(model, agent_portrayal) elif space_drawer: # if specified, draw agent space with an alternate renderer space_drawer(model, agent_portrayal) @@ -296,7 +302,11 @@ def portray(g): x.append(i) y.append(j) if "size" in data: - s.append(max(data["size"] + delta, data["min_size"])) + if data["min_size"]: + s.append(max(data["size"] + delta, data["min_size"])) + else: + s.append(max(data["size"] + delta, 5)) + if "color" in data: c.append(data["color"]) out = {"x": x, "y": y} @@ -306,6 +316,7 @@ def portray(g): out["c"] = c return out + # figure(figsize=(50, 50), dpi=80) space_fig = Figure() space_ax = space_fig.subplots() if isinstance(model.grid, mesa.space.NetworkGrid):