Skip to content

Allow image markers to plot agents #2799

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Holzhauer
Copy link
Contributor

Summary

Enable images as markers for plotting agents and apply the feature to the Schelling model example

Motive

In may cases images are a preferable means to distinguish agents in the visualisation.

Implementation

In _scatter() it is checked whether the value for marker contains a valid file resource. If so, an image is created and zoomed (_get_zoom_factor) to the size of a grid cell (it is required to postpone calls of _scatter() in draw* methods because x and y limits need to be set earlier). An AnnotationBbox is used to display the image on the grid.

Usage Examples

The Schelling model was updated to apply image markers (and AgentPortrayalStyle) depending on agent type and state:

Schelling_before
Schelling_after

(Agents' step method was changed and assign_state introduced. Now the initial number of happy agents is shown correctly in the figure.)

Additional Notes

It seems that figure size is adjusted in solara after its initilisation. That's why CORRECTION_FACTOR_MARKER_ZOOM = 0.6 was introduced. There might be a better approach...

Holzhauer added 2 commits May 28, 2025 13:43
- add image marker
- postpone call of _scatter() in draw* method because limits need to be
set earlier
- add _get_zoom_factor to achieve correct image size
- add agent attribute 'happy'
- add emoticon PNGs
- correct Readme.md
- adapt agents step method and introduce assign_state
- setup use of image markers in app.py
- call agent methods in model.py
Copy link

Performance benchmarks:

Model Size Init time [95% CI] Run time [95% CI]
BoltzmannWealth small 🔴 +4.7% [+4.0%, +5.3%] 🔵 -0.2% [-0.4%, +0.0%]
BoltzmannWealth large 🔵 -0.5% [-1.2%, +0.1%] 🔵 +0.1% [-2.8%, +3.0%]
Schelling small 🔴 +40.6% [+40.3%, +40.8%] 🔵 -2.2% [-2.4%, -1.9%]
Schelling large 🔴 +119.6% [+117.7%, +122.0%] 🟢 -13.5% [-14.6%, -12.6%]
WolfSheep small 🔵 +0.6% [+0.2%, +1.1%] 🔵 -0.1% [-0.3%, +0.2%]
WolfSheep large 🔵 +0.2% [-0.4%, +0.9%] 🔵 -0.0% [-1.1%, +1.0%]
BoidFlockers small 🔵 -0.3% [-0.9%, +0.4%] 🔵 -1.4% [-1.7%, -1.2%]
BoidFlockers large 🔵 -1.8% [-2.1%, -1.4%] 🔵 -2.3% [-2.6%, -1.9%]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant