FIX: keep SVG axes siblings when ending draw with rasterized artists by ShamikOfficial · Pull Request #32311 · matplotlib/matplotlib · GitHub
Skip to content

FIX: keep SVG axes siblings when ending draw with rasterized artists - #32311

Merged
QuLogic merged 3 commits into
matplotlib:mainfrom
ShamikOfficial:fix/32174-svg-rasterized-zorder-axes
Oct 20, 2026
Merged

QuLogic merged 3 commits into
matplotlib:mainfrom
ShamikOfficial:fix/32174-svg-rasterized-zorder-axes

Conversation

@ShamikOfficial

Copy link
Copy Markdown
Contributor

PR summary

Closes #32174.

When the last artist drawn in an Axes uses rasterized=True, mixed-mode rendering can still be active when Axes.draw calls close_group('axes'). MixedModeRenderer was proxying that call to the Agg raster renderer, where close_group is a no-op. The SVG axes group therefore stayed open, so the next axes was nested inside it.

This mirrors the existing close_blend_group handling: if rasterization can be stopped (_raster_depth == 0), flush to the vector backend before closing the group. Nested close_group calls from rasterized artists still run at _raster_depth > 0, so consecutive rasterized artists can still merge into one image.

AI Disclosure

Cursor was used to help locate the mixed-mode grouping bug, implement the flush-before-close_group fix, and add the regression test. I reviewed the change and verified the issue reproduction and the fix locally.

PR quality check

  • Use an expressive title, e.g. "Fix title font property precedence"
  • New and changed code is tested
  • [N/A] Plotting related features are demonstrated in an example
  • [N/A] New features and API changes have release notes
  • [N/A] Documentation complies with general and docstring guidelines

Pending mixed-mode rasterization left Axes.close_group on the Agg
renderer, so SVG axes groups stayed open and later axes nested inside
them when artists used rasterized=True. Closes matplotlib#32174.

Co-authored-by: Cursor <cursoragent@cursor.com>

@ayshih ayshih left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! Just one suggestion for a comment to assist future maintenance

Comment thread lib/matplotlib/tests/test_backend_svg.py
Co-authored-by: Albert Y. Shih <ayshih@gmail.com>
@QuLogic
QuLogic merged commit 0783226 into matplotlib:main Oct 20, 2026
40 of 41 checks passed
@lumberbot-app

lumberbot-app Bot commented Oct 20, 2026

Copy link
Copy Markdown

@QuLogic

QuLogic commented Oct 21, 2026

Copy link
Copy Markdown
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Using rasterized=True with zorder makes the generated SVG have wrong axes layer hierarchy

5 participants