Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Bug]: Rasterized Artists in DrawingArea will be misplaced in the vectorized backend #28549

Open
@Mr-Milk

Description

@Mr-Milk

Bug summary

If I rasterized artists in DrawingArea, they are rendered correctly in rasterized backend but will be misplaced in the vectorized backend

Code for reproduction

import matplotlib.pyplot as plt
from matplotlib.offsetbox import AnchoredOffsetbox, DrawingArea
from matplotlib.patches import Rectangle
from matplotlib.collections import PatchCollection

for backend in ["png", "pdf", "svg"]:
    for rasterized in [True, False]:
        fig, ax = plt.subplots(figsize=(2, 2))
        box = DrawingArea(10, 10)
        rects = PatchCollection([
            Rectangle((0, i), width=10, height=1, ec="red")
            for i in range(10)
        ])
        rects.set_rasterized(rasterized)
        box.add_artist(rects)
        canvas = AnchoredOffsetbox(child=box, loc="center", pad=0)
        ax.add_artist(canvas)
        fig.savefig(f"DA_rasterized={rasterized}.{backend}")

Actual outcome

When set rasterized=True and in backend svg or pdf:
image

In other situations, it's properly render:
image

Expected outcome

This is expected in any situation:
image

Additional information

No response

Operating system

OS/X arm

Matplotlib Version

3.9.1

Matplotlib Backend

module://matplotlib_inline.backend_inline

Python version

3.10.13

Jupyter version

4.1.1

Installation

pip

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions