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

Skip to content

Conversation

AasmaGupta
Copy link
Contributor

@AasmaGupta AasmaGupta commented Aug 29, 2025

Reference issue (if any)

Example: AttributeError: 'FigureCanvasSVG' object has no attribute 'copy_from_bbox'

Fixes #30485

  • Why is this change necessary?
    Saving figures as SVG could crash due to the way def update_background handled blitting in the lib/matplotlib/widgets.py file. This change prevents that crash.

  • What problem does it solve?
    fixes the crash that occurred specifically when exporting plots to SVG format

  • What is the reasoning for this implementation?
    Blitting is meant for interactive updates and isn’t needed when saving static outputs. Skipping it during SVG export prevents the crash while keeping normal interactive behavior intact.

PR checklist

@AasmaGupta
Copy link
Contributor Author

i tested the fix using the code below which reproduces the issue and confirms that SVG export no longer crashes:

import numpy as np
import matplotlib

matplotlib.use("Agg")  
import matplotlib.pyplot as plt
from matplotlib.widgets import SpanSelector

fig, ax = plt.subplots()
ax.plot(np.random.randn(100, 3))
ax._span = SpanSelector(ax, lambda xmin, xmax: None, "horizontal", useblit=True)

fig.savefig("test.svg")

print("Saved successfully without crash!")

@AasmaGupta AasmaGupta force-pushed the fix-svg-error branch 4 times, most recently from fd2cfb4 to 3d6e31c Compare August 29, 2025 23:44
@AasmaGupta AasmaGupta closed this Aug 29, 2025
@QuLogic
Copy link
Member

QuLogic commented Aug 30, 2025

There is no such thing as _setup_plot_projector in Matplotlib; what is this actually about?

@AasmaGupta AasmaGupta changed the title Fix SVG rendering error in _setup_plot_projector Fix SVG rendering error in def update_backgroud Aug 30, 2025
@AasmaGupta AasmaGupta changed the title Fix SVG rendering error in def update_backgroud Fix SVG rendering error in def update_background Aug 30, 2025
@AasmaGupta
Copy link
Contributor Author

I have updated the PR with the issue number and more accurate files and functions to navigate the issue as well as the fix. Hope this makes it easier to navigate and review!

@tacaswell tacaswell added this to the v3.10.7 milestone Sep 2, 2025
Copy link
Member

@tacaswell tacaswell left a comment

Choose a reason for hiding this comment

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

@AasmaGupta Do you feel comfortable squashing this to one commit? IF not we can squash-merge.

Otherwise 👍

@AasmaGupta
Copy link
Contributor Author

@tacaswell I'm fine with you squash merging it from your end. Thanks!

@tacaswell tacaswell merged commit 0056a47 into matplotlib:main Sep 2, 2025
39 of 40 checks passed
meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull request Sep 2, 2025
timhoffm added a commit that referenced this pull request Sep 2, 2025
…490-on-v3.10.x

Backport PR #30490 on branch v3.10.x (Fix SVG rendering error in def update_background)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: figures with SpanSelector(..., useblit=True) can't be saved to SVG or PDF
4 participants