Skip to content

Refactoring mesa.visualization.components.matplotlib #2401

Closed
@quaquel

Description

@quaquel

I have taken a closer look at the solara matplotlib visualization support in MESA and tried to refactor it a bit because of various redundancies. However, I ran into a few issues. Basically, how the data is gathered before plotting is dependent on the type of space that is to be visualized. For example, there is no relevant position data when visualizing networks. Offsets to x and y are added for grids. Moreover, for discrete spaces, we have multiple implementations of both old-style and new-style (e.g., HexSingleGrid, HexMultiGrid, HexGrid). I believe it is quite easy to abstract away whether you are plotting an old-style or a new-style space. They mainly differ with respect to how you get the agents to plot and their (x, y) coordinates, which is easily wrapped into custom generators (these generators are probably also useful for the altair side of things, so I'll probably add a components.util module).

In an attempt to make sense of this all, I have come to the following breakdown:

OrthogonalGrid = SingleGrid | MultiGrid | OrthogonalMooreGrid | OrthogonalVonNeumannGrid
HexGrid = HexSingleGrid | HexMultiGrid | HexGrid
ContinousSpace
Network = NetworkGrid | mesa.experimental.grid_space.Network 
VoronoiGrid

draw_orthogonal_grid(space: OrthogonalGrid, agent_portrayal: Callable, propertylayer_portrayal: Callable)
    ...

draw_hex_grid(space: HexGrid, agent_portrayal: Callable, propertylayer_portrayal: Callable):
    ...

draw_network(space: Network, agent_portrayal: Callable, propertylayer_portrayal: Callable):
    ...

draw_continuous_space(space: ContinousSpace, agent_portrayal: Callable):
    ...


draw_voroinoi_grid(space: VoronoiGrid, agent_portrayal: Callable, propertylayer_portrayal: Callable):
    ...

I have several questions:

  1. Does the breakdown into types of spaces make sense?
  2. Did I miss anything?
  3. Property layers are currently implemented in DiscreteSpace for new-style spaces. So they are available in all new style spaces, including Network and VoronoiGrid. Should property grids be moved from DiscreteSpace to Grid? This would mimic old-style spaces. I also question whether property layers are presently meaningful for networks or Voronoi meshes. (I want to focus the conversation on improving the current visualization code, so please don't bring up ideas on how to expand property layers to also work in e.g., VoronoiGrid or continuous spaces).

If this brake down makes sense, I'll reorganize the code accordingly and start writing some tests for it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions