-
Notifications
You must be signed in to change notification settings - Fork 880
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
Visualize PropertyLayers #2336
Visualize PropertyLayers #2336
Conversation
for more information, see https://pre-commit.ci
This comment was marked as off-topic.
This comment was marked as off-topic.
62be7da
to
a7dbe0a
Compare
This is ready for a first round of review, API wise its done. Any conceptual, feature or API feedback is welcome. If no major things come up, I will finish the tests and such. The GoL example is also available here: projectmesa/mesa-examples#214 |
When adding "colorbar": False to a propertylayer_portrayal, it turns of the colorbar.
for more information, see https://pre-commit.ci
visualisation of PropertyLayers the ContiniousGrid and Vonoroid space could be added later
This comment was marked as off-topic.
This comment was marked as off-topic.
Going to merge this, it breaks nothing and adds a new feature. Post-merge review still appreciated! |
This is not fine. You are breaking the convention of a review needed into a new feature that is not experimental. This is definitely not fair to other developers who have waited for a long time even for a review, e.g. @wang-boyu with the recent Mesa-Geo stuff, even though he is the lead maintainer on the repo. |
It’s a valid concern. I wanted to include it in the beta, so users could start testing it and delivering feedback, and updating example models (like projectmesa/mesa-examples#214). I thought I had an approval on the API for this PR and #2341 from @quaquel. @projectmesa/maintainers I would like your perspective on how to handle cases like this, for if they happen in the future. |
space = getattr(model, "space", None) | ||
|
||
if isinstance(space, mesa.space._Grid): | ||
_draw_grid(space, space_ax, agent_portrayal, propertylayer_portrayal, model) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Either of:
- Why pass an entire model instead of just the layers?
- Why not use the space argument and access it from the model instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Edit: s/Why not use the space/Why not remove the space/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the review and the questions, I will try to look into them soon.
Also feel free to open a PR if you already have concrete solutions in mind.
Edit: Yeah I now remind, there are some inconsistencies between the draw functions here. When I add support for other spaces I will try to address these.
This PR adds support for visualizing PropertyLayers in the Matplotlib-based space visualization component. It allows users to overlay PropertyLayer data on top of the existing grid and agent visualizations, or on its own.
It introduces a new
propertylayer_portrayal
parameter to customize the appearance of PropertyLayers and refactors the existing space visualization code for better modularity and flexibility.Motive
The PropertyLayer is becoming a key feature in Mesa, so it should be visualized easily. This feature enables users to easily visualize multiple layers of data simultaneously, such as environmental factors or agent properties, alongside the agents themselves.
Implementation
propertylayer_portrayal
parameter to themake_space_matplotlib
function.draw_property_layers
function to render PropertyLayer data using Matplotlib'simshow
._draw_grid
function to incorporate PropertyLayer visualization before drawing agents.Usage Examples
You can visualize multiple PropertyLayers ("grass" and "temperature" in this case) along with agents in a grid space:
You can also use a single color for a PropertyLayer. Here we render the "cell_layer" PropertyLayer using shades of black, with the highest value having 0% opacity and the lowest value having 100% opacity. For Game of Life that means alive cells are fully black, and dead cells transparent.
Any matplotlib color is valid. The highest value will have that color with 0% opacity, the lowest with 100% opacity (which can again be scaled with modifying
vmin
andvmax
).Additional Notes
colorbar
parameter in the portrayal dictionary.TODO
Closes #2138.