Repository navigation
Let post_process customize the x axis of matplotlib plots - #4086
Merged
Merged
Conversation
PlotMatplotlib called post_process(ax) before it set the x label to
"Step" and the x tick locator to MaxNLocator(integer=True). Any x label
or x tick change made in post_process was therefore overwritten, for
example ax.set_xlabel("Time Step") in tutorials 8 and 9.
Call post_process last, after the defaults, as SpaceMatplotlib and
PlotAltair already do. Plots without post_process look the same.
|
Performance benchmarks:
|
quaquel
approved these changes
Nov 14, 2026
EwoutH
pushed a commit
that referenced
this pull request
Nov 22, 2026
#4086) PlotMatplotlib called post_process(ax) before it set the x label to "Step" and the x tick locator to MaxNLocator(integer=True). Any x label or x tick change made in post_process was therefore overwritten, for example ax.set_xlabel("Time Step") in tutorials 8 and 9. Call post_process last, after the defaults, as SpaceMatplotlib and PlotAltair already do. Plots without post_process look the same. (cherry picked from commit 257aebf)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Pre-PR checklist
Summary
This PR fixes an issue where changes made to the x-axis through
post_processwere being overwritten when using Mesa's default Matplotlib backend.The problem was caused by
PlotMatplotlibapplying its default x-axis label and tick locator after running the custompost_processfunction. Moving the function call after the default axis setup ensures that user customizations are preserved.Bug / Issue
There is no linked issue for this change. This is a small, self-contained bug fix with a minimal reproducer.
The issue is also present in Mesa's visualization tutorials 8 and 9. Both use
post_processto set the x-axis label to"Time Step", but the rendered chart still displays"Step".The same problem affects custom tick locators. For example, setting
MultipleLocator(10)insidepost_processgets overwritten by Mesa's defaultMaxNLocator(integer=True).Implementation
Updated
PlotMatplotlibinmesa/visualization/components/matplotlib_components.py.The default x-axis label and tick locator are now configured before calling
post_process. This allows custom changes made through the callback to remain on the rendered chart.No changes were needed to the public API, and charts that do not use
post_processretain their existing behaviour.Testing
Added
test_plot_matplotlib_post_process_can_change_x_axistotests/visualization/test_components_matplotlib.py.The test checks that:
"Step"label and integer tick locator are preserved whenpost_processdoes not modify the x-axis."Time Step") is retained.MultipleLocatoris not overwritten.Before/after verification:
The reproducer uses Mesa's Boltzmann wealth model and the
post_process_linesfunction from tutorial 8.Expected results:
Additional notes
3.5.x-maintenancebranch.