viz: Automatically visualize Cell color attributes in cell space #2558
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Adds automatic visualization of a Cell's
color
attribute in Mesa's matplotlib-based visualization. When a Cell has acolor
attribute set to any valid matplotlib color, it will now be automatically displayed in the visualization without requiring manual configuration.Motive
Currently, visualizing properties of Cells in cell spaces requires manual configuration of the visualization code. This can be cumbersome, especially for the common case of wanting to display cells in different colors. By automatically detecting and visualizing the
color
attribute, we make it much easier for users to create visually informative cell-based models.The PR aligns with Mesa's philosophy of providing sensible defaults while maintaining flexibility - users can still override the visualization behavior if needed, but get reasonable visualization out of the box.
Implementation
The implementation modifies the
draw_orthogonal_grid()
anddraw_hex_grid()
functions to:all_cells
attributecolor
attributeChanges are backward compatible - spaces without cells or cells without colors are rendered exactly as before.
Usage Examples
Simple usage:
The visualization automatically shows green cells turning red as fire spreads, no additional visualization code needed.
Screenshots comparing visualization:
Before (manually configuring colors):
After (automatic color visualization):
TODO: [Screenshots]
Additional Notes
Closes #2557