Skip to content

SolaraViz: Use _get_agent_data consistently in visualisation of all spaces #2407

@EwoutH

Description

@EwoutH

The Visualize PropertyLayers PR (#2336) added a new internal function _get_agent_data to the visualization/components/matplotlib.py module. This function gathers data from the agent_portrayal dict, while handling synonyms and ommitted data.

Currently only drawing the grid uses it, but ideally, all spaces would use it.

A concrete example, is that currently if you omit "size" in your agent_portrayal dict, you get this non-obvious error:

  File "C:\Users\Ewout\Documents\GitHub\mesa\mesa\visualization\components\matplotlib.py", line 67, in SpaceMatplotlib
    _draw_discrete_space_grid(space, space_ax, agent_portrayal)
  File "C:\Users\Ewout\Documents\GitHub\mesa\mesa\visualization\components\matplotlib.py", line 335, in _draw_discrete_space_grid
    space_ax.scatter(**portray(space))
  File "C:\Users\Ewout\.virtualenvs\Py312\Lib\site-packages\matplotlib\__init__.py", line 1473, in inner
    return func(
           ^^^^^
  File "C:\Users\Ewout\.virtualenvs\Py312\Lib\site-packages\matplotlib\axes\_axes.py", line 4796, in scatter
    raise ValueError(
ValueError: s must be a scalar, or float array-like with the same size as x and y

Adding something like

    portrayal = {
        "s": 25,
        ...

does not fix the issue, since you need to add "size", since we internally translate that.

_get_agent_data does not only also check for "s", but it also includes default values for when it's omitted.

This issue is probably related to:

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