From 31fa87dd4bdbbcd6f5ece57a1d0fffc2039848c7 Mon Sep 17 00:00:00 2001 From: Aarav Shukla Date: Wed, 29 Jan 2025 16:40:29 +0530 Subject: [PATCH 1/4] Update Binder environment to use latest Mesa version (#2652) --- binder/environment.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/binder/environment.yml b/binder/environment.yml index 00f316343ff..20759c3e5ec 100644 --- a/binder/environment.yml +++ b/binder/environment.yml @@ -1,8 +1,8 @@ -name: example-environment +name: mesa-tutorials channels: - conda-forge dependencies: - - python + - python=3.9 - numpy - pip - pip: @@ -11,4 +11,4 @@ dependencies: - matplotlib - seaborn - solara - - mesa[rec]==3.0.0b1 + - mesa[rec] From 68d5dc8a36113fbdda453901a2ec7db70572c2fa Mon Sep 17 00:00:00 2001 From: Aarav Shukla Date: Fri, 31 Jan 2025 17:39:30 +0530 Subject: [PATCH 2/4] Remove pinned Python version and ensure compatibility with Python >=3.11 --- binder/environment.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/binder/environment.yml b/binder/environment.yml index 20759c3e5ec..4e13922fa81 100644 --- a/binder/environment.yml +++ b/binder/environment.yml @@ -2,7 +2,7 @@ name: mesa-tutorials channels: - conda-forge dependencies: - - python=3.9 + - python - numpy - pip - pip: From 2740d3f557eae30ed6b3e93e4c13996de3df349d Mon Sep 17 00:00:00 2001 From: Aarav Shukla Date: Sat, 1 Feb 2025 17:54:41 +0530 Subject: [PATCH 3/4] Refactored draw_space to separate grid, properties, and agents (#2638) --- mesa/visualization/mpl_space_drawing.py | 29 ++++++++++++++++--------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/mesa/visualization/mpl_space_drawing.py b/mesa/visualization/mpl_space_drawing.py index ea7687c4210..bfc60c5192d 100644 --- a/mesa/visualization/mpl_space_drawing.py +++ b/mesa/visualization/mpl_space_drawing.py @@ -107,7 +107,9 @@ def draw_space( space, agent_portrayal: Callable, propertylayer_portrayal: dict | None = None, - ax: Axes | None = None, + ax_grid: Axes | None = None, + ax_properties: Axes | None = None, + ax_agents: Axes | None = None, **space_drawing_kwargs, ): """Draw a Matplotlib-based visualization of the space. @@ -127,34 +129,41 @@ def draw_space( "size", "marker", "zorder", alpha, linewidths, and edgecolors. Other field are ignored and will result in a user warning. """ - if ax is None: - fig, ax = plt.subplots() + if ax_grid is None: + fig, ax_grid = plt.subplots() # https://stackoverflow.com/questions/67524641/convert-multiple-isinstance-checks-to-structural-pattern-matching match space: # order matters here given the class structure of old-style grid spaces case HexSingleGrid() | HexMultiGrid() | mesa.experimental.cell_space.HexGrid(): - draw_hex_grid(space, agent_portrayal, ax=ax, **space_drawing_kwargs) + draw_hex_grid(space, agent_portrayal, ax=ax_grid, **space_drawing_kwargs) case ( mesa.space.SingleGrid() | OrthogonalMooreGrid() | OrthogonalVonNeumannGrid() | mesa.space.MultiGrid() ): - draw_orthogonal_grid(space, agent_portrayal, ax=ax, **space_drawing_kwargs) + draw_orthogonal_grid(space, agent_portrayal, ax=ax_grid, **space_drawing_kwargs) case mesa.space.NetworkGrid() | mesa.experimental.cell_space.Network(): - draw_network(space, agent_portrayal, ax=ax, **space_drawing_kwargs) + draw_network(space, agent_portrayal, ax=ax_grid, **space_drawing_kwargs) case mesa.space.ContinuousSpace(): - draw_continuous_space(space, agent_portrayal, ax=ax) + draw_continuous_space(space, agent_portrayal, ax=ax_grid) case VoronoiGrid(): - draw_voronoi_grid(space, agent_portrayal, ax=ax) + draw_voronoi_grid(space, agent_portrayal, ax=ax_grid) case _: raise ValueError(f"Unknown space type: {type(space)}") if propertylayer_portrayal: - draw_property_layers(space, propertylayer_portrayal, ax=ax) + if ax_properties is None: + ax_properties = ax_grid + draw_property_layers(space, propertylayer_portrayal, ax=ax_properties) - return ax + if hasattr(space, "agents") and space.agents: + if ax_agents is None: + ax_agents = ax_grid + draw_agents(space, agent_portrayal, ax=ax_agents) + + return ax_grid def draw_property_layers( From 0e1bc443c13fed57c0e2c70db1edf8cb7a7192a9 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 1 Feb 2025 12:59:24 +0000 Subject: [PATCH 4/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- mesa/visualization/mpl_space_drawing.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mesa/visualization/mpl_space_drawing.py b/mesa/visualization/mpl_space_drawing.py index b070522fed4..37c61da150c 100644 --- a/mesa/visualization/mpl_space_drawing.py +++ b/mesa/visualization/mpl_space_drawing.py @@ -143,7 +143,9 @@ def draw_space( | OrthogonalVonNeumannGrid() | mesa.space.MultiGrid() ): - draw_orthogonal_grid(space, agent_portrayal, ax=ax_grid, **space_drawing_kwargs) + draw_orthogonal_grid( + space, agent_portrayal, ax=ax_grid, **space_drawing_kwargs + ) case mesa.space.NetworkGrid() | mesa.experimental.cell_space.Network(): draw_network(space, agent_portrayal, ax=ax_grid, **space_drawing_kwargs) case mesa.space.ContinuousSpace():