-
Notifications
You must be signed in to change notification settings - Fork 940
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draw space(#2638) #2657
Draw space(#2638) #2657
Changes from all commits
31fa87d
68d5dc8
2740d3f
904fdf7
0e1bc44
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -108,7 +108,9 @@ def draw_space( | |
space, | ||
agent_portrayal: Callable, | ||
propertylayer_portrayal: dict | None = None, | ||
ax: Axes | None = None, | ||
ax_grid: Axes | None = None, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not convinced that this is the ideal solution for an improved API. You now have to pass the axes multiple times in the most common use case. I suggest we hatch out the API design in #2640 first before opening a PR. |
||
ax_properties: Axes | None = None, | ||
ax_agents: Axes | None = None, | ||
**space_drawing_kwargs, | ||
): | ||
"""Draw a Matplotlib-based visualization of the space. | ||
|
@@ -127,37 +129,43 @@ 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) | ||
case ( | ||
mesa.space.ContinuousSpace() | ||
| mesa.experimental.continuous_space.ContinuousSpace() | ||
): | ||
draw_continuous_space(space, agent_portrayal, ax=ax) | ||
draw_network(space, agent_portrayal, ax=ax_grid, **space_drawing_kwargs) | ||
case mesa.space.ContinuousSpace(): | ||
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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a good name for a new method. But I don't see an implementation of draw_agents at the moment? |
||
|
||
return ax_grid | ||
|
||
|
||
@lru_cache(maxsize=1024, typed=True) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please keep PRs focussed, this is a separate issue and thus does not belong in this PR. I suggest reverting all changes to this file