Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
Back to tool/Back to issues
#32174·matplotlib

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

Author: ahmedselim2017Created Aug 6, 2026Updated Sep 23, 2026
Labelsbackend: svgfirst-contribution

Bug summary

Hi, while using rasterized=True with the zorder, the saved svg files have a wrong axes layer hierarchy:

However, interestingly if another drawing command is called after such as ax.scatter(x=[], y=[], rasterized=False, zorder=10) with the same zorder but without rasterization, the generated svg file has correct layer hierarchy.

Code for reproduction

python
import matplotlib.pyplot as plt

fig, axs = plt.subplots(ncols=2)
for i, ax in enumerate(axs):
    ax.scatter(x=[1, 2], y=[1, 2], rasterized=True, zorder=10)
fig.savefig("minimal_not_working.svg")

fig, axs = plt.subplots(ncols=2)
for i, ax in enumerate(axs):
    ax.scatter(x=[1, 2], y=[1, 2], rasterized=True, zorder=10)
    ax.scatter(x=[], y=[], rasterized=False, zorder=10)
fig.savefig("minimal_working.svg")

Actual outcome

Axes layer hierarchy of minimal_not_working.svg:

- figure_1
  - axes_1
    - [ parts of the axes_1 ] 
    - axes_2
      - [ parts of the axes_2 ] 

Axes layer hierarchy of minimal_working.svg:

- figure_1
  - axes_1
    - [ parts of the axes_1 ] 
  - axes_2
    - [ parts of the axes_2 ] 

Expected outcome

The minimal_not_working.svg should have an axes layer hierarchy simlar to:

- figure_1
  - axes_1
    - [ parts of the axes_1 ] 
  - axes_2
    - [ parts of the axes_2 ] 

Additional information

No response

Operating system

No response

Matplotlib Version

3.11.1

Matplotlib Backend

No response

Python version

No response

Jupyter version

No response

Installation

None

Source: matplotlib/matplotlib

View original on GitHubView discussion on GitHub