Skip to content

Update SpaceRenderer API in Tutorials 4, 5, and 6#3231

Merged
quaquel merged 5 commits intomesa:mainfrom
falloficarus22:migrate-tutorials
Feb 4, 2026
Merged

Update SpaceRenderer API in Tutorials 4, 5, and 6#3231
quaquel merged 5 commits intomesa:mainfrom
falloficarus22:migrate-tutorials

Conversation

@falloficarus22
Copy link
Copy Markdown
Contributor

Summary

This PR migrates several Mesa tutorials (4, 5, and 6) to the new SpaceRenderer API. It resolves deprecation warnings by replacing the older draw_* methods and parameterized render() calls with the recommended setup_* methods and a parameterless render() call

Bug / Issue

The tutorials were still using the deprecated visualization API. Specifically:

  • They used draw_structure() and draw_agents() instead of the new setup_structure() and setup_agents() methods.They passed portrayal arguments directly to .render(), which is now deprecated in favor of a "setup then render" workflow.
  • This causes PendingDeprecationWarning and FutureWarning for users following the tutorials and inconsistent teaching of the library's best practices.

Implementation

Updated the following Jupyter notebooks:

  1. docs/tutorials/4_visualization_basic.ipynb:
    • Updated Cell 16 to use method chaining for setup: .setup_agents(agent_portrayal).render().
  2. docs/tutorials/5_visualization_dynamic_agents.ipynb:
    • Updated Cell 14 to use: .setup_agents(agent_portrayal).render().
  3. docs/tutorials/6_visualization_rendering_with_space_renderer.ipynb:
    • Code Cells 15 & 18: Migrated both Matplotlib and Altair examples to the multi-step pattern: setup_structure(...), setup_agents(...), and then render().Markdown Cells: Updated all text references to reflect the method name changes (changing draw_structure() to setup_structure() and draw_agents() to setup_agents()) to ensure instructional consistency.

Testing

  • Verified that all code changes align with the implementation source in mesa/visualization/space_renderer.py.
  • Checked that Markdown references correctly match the updated code snippets.

If you're fixing the visualisation, add before/after screenshots. -->

Additional Notes

This migration ensures that the "setup then render" paradigm is taught consistently across all core spatial visualization tutorials.
Closes #3228

falloficarus22 and others added 4 commits January 30, 2026 15:30
Migrates the visualization tutorials to use the new SpaceRenderer API
(setup_structure, setup_agents, and render() without arguments).
This resolves deprecation warnings and aligns the documentation with
the latest visualization workflow.

- docs/tutorials/4_visualization_basic.ipynb: Update to setup_agents()
- docs/tutorials/5_visualization_dynamic_agents.ipynb: Update to setup_agents()
- docs/tutorials/6_visualization_rendering_with_space_renderer.ipynb: Update to setup_* methods and Markdown descriptions.
@quaquel quaquel added the docs Release notes label label Feb 1, 2026
@quaquel quaquel merged commit a5895ed into mesa:main Feb 4, 2026
12 of 13 checks passed
@falloficarus22 falloficarus22 deleted the migrate-tutorials branch February 5, 2026 03:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Release notes label

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tracking Issue: Update SpaceRenderer API in All Tutorials

2 participants