Skip to content

PropertyLayer Visualization is Broken in HexGrids #2859

@flucco

Description

@flucco

Bug Description

Note on coordinates: In Mesa, 2D PropertyLayer arrays have shape (width, height), and so (row, column) in a PropertyLayer array = (x,y) in the grid.

In the latest version of the build, when using the Matplotlib backend for Solara visualization, the values of a PropertyLayer don't show up in the right places on a HexGrid. The color associated with (x,y) will not appear at (x,y) in the hexagonal grid shown on the screen.*

What I would expect is that everything associated with the grid cell (x,y), such as agents and PropertyLayer values, should appear at (x,y) in the visualization. This is how the visualization of an orthogonal Grid behaves.

As far as I can tell, it's the visualization that has an issue, not the HexGrid class itself.

*Precisely, the color value layout is what you would get if you matched a flattened (W x H) array of color values to a flattened (H x W) array of grid cells those color values should correspond to.

Reproduction

I created a modified version of the Sugarscape example to show this bug. I changed the backend to matplotlib and the grid to a HexGrid for the last two screenshots. I also added a file "sugarscape-asymmetrical.txt", which is a version of "sugarscape.txt" with several rows zeroed out. This creates a white line in the grid. It's much easier to see the bug this way.

Behavior with Orthogonal Grid

Appearance of visualization at start:

Image

Note the position of the white stripe.

Appearance of visualization at timestep 1:

Image

We can see that agents are in white squares because they eat whatever's in their square.

Behavior with Hexagonal Grid

Appearance of visualization at start:

Image

The white stripe is clearly in the wrong place.

Appearance of visualization at timestep 1:

Image

We can see that white squares appear, but not where the agents are. This is because the color values are assigned to the wrong grid cells, whereas the agents are shown in the correct grid cells.

Note: In the original "sugarscape.txt" distribution, the grids look identical at the start (minus the small differences caused by the hexagonal layout). But once you run the simulation, you can see the same bug in the HexGrid, where white squares appear in different places than agents.

Exact Reproduction Details

The changes are very simple (like five lines total). I put the modified example in the examples directory of a branch in my fork of the Mesa code.

Changes to actual code:

  1. In app.py, change the app backend to matplotlib:
    a. When making the SpaceRenderer, set backend = "matplotlib" instead of "altair"
    b. Modify the post_process code, as Axes doesn't have the same methods as Chart. I added code to make the aspect ratio equal and take out the x and y ticks.
  2. In model.py, import HexGrid. To see the bug, initialize the grid as a Hexgrid instead of an Orthogonal Von Neumann Grid.
  3. Also in model.py, to view the asymmetrical example: change "sugar-map.txt" to "sugar-map-asymmetrical.txt"

Added file "sugar-map-asymmetrical.txt":

  1. Changed all the values in a chunk of rows (7-12) to zeroes.

Additional context

  • I tested this bug in the latest build of Mesa as of 10/24/2025, using an unedited fork of the main branch.
  • I updated to the latest version of Solara as of 10/24/2025
  • I have Windows 11. I ran Solara in the latest version of Firefox. (The same bug occurs in Microsoft Edge, and in a Jupyter notebook)
  • I searched for similar issues, but I might have missed something as there's a lot to look through. The only thing I found was a resolved issue about the display of the hexagons themselves, which don't appear to be an issue now (agents appear in the right places).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions