ENH: Add screen-proportional mutation_aspect to FancyBboxPatch - #32205
Open
Muhtasim-Munif-Fahim wants to merge 1 commit into
Open
ENH: Add screen-proportional mutation_aspect to FancyBboxPatch#32205Muhtasim-Munif-Fahim wants to merge 1 commit into
Muhtasim-Munif-Fahim wants to merge 1 commit into
Conversation
Add opt-in "screen-proportional" mode to FancyBboxPatch.mutation_aspect that resolves the display-space aspect ratio from the axes at draw time. Rounded corners of Round/other boxstyles then render circular on screen regardless of the axes aspect ratio, without requiring the private ax._get_aspect_ratio() workaround. Closes matplotlib#31175.
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.
PR summary
What problem existed
FancyBboxPatchrequires a numericmutation_aspectto compensate for a non-unit axes aspect ratio. In a plot withaspect="auto"(e.g. a typical bar chart), the rounding ofBoxStyle("Round", ...)is drawn as an ellipse on screen, not a circle. The only way to get isotropic rounding was the private workaroundmutation_aspect=1/ax._get_aspect_ratio(), which is also computed too early (before layout) and therefore stale by draw time.How it was reproduced
What caused it
FancyBboxPatch.get_path()appliesmutation_aspectin data coordinates only. When the axes display scaling differs between x and y (aspect != 1), a data-space circle is drawn as an on-screen ellipse. There was no public way to opt in to resolving the aspect ratio from the axes.What changed
FancyBboxPatch.mutation_aspectnow additionally accepts the string"screen-proportional". At draw time the patch resolves it from the owning axes using public API (get_window_extent, axis transforms), so the box is scaled like the data on screen and the rounding renders circular regardless of the axes aspect ratio.set_mutation_aspectvalidates the new value.Why this approach
The issue proposed an opt-in mode; discussion suggested a name that is more specific than a generic
"auto". The resolution is deferred to draw time so the layout (and thus the display scaling) is final, fixing the stale-value problem of the private-API workaround. All existing numeric behavior is unchanged.How it was tested
python -m pytest lib/matplotlib/tests/test_patches.py -k "mutation_aspect" -v→ 1 passedpython -m pytest lib/matplotlib/tests/test_patches.py→ 73 passed, 11 skipped (pre-existing skips)ValueErroron invalid values.Risks / limitations
"screen-proportional"falls back to an aspect of 1 (documented in the new tests).Related issue
Closes #31175