GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [Bug]: High memory usage in `Figure.savefig` · Issue #29434 · matplotlib/matplotlib

[Bug]: High memory usage in Figure.savefig #29434

New issue
Copy link
New issue
Copy link
Open
Open
[Bug]: High memory usage in Figure.savefig#29434
Copy link
Labels
DocumentationPerformance

Description

@zqianem
zqianem
opened on Jan 8, 2025
Issue body actions

Bug summary

When saving figures with large data images (imshow), matplotlib version 3.10.0 uses ~4.2 times the amount of memory, and runs ~2.5 times slower.

Code for reproduction

#!/usr/bin/env -S uv run --with humanize --with numpy --with "matplotlib==3.10"

import tracemalloc

import humanize
import matplotlib.pyplot as plt
import numpy as np

tracemalloc.start()

fig, ax = plt.subplots()
ax.imshow(np.zeros((10_000, 10_000)))

fig.savefig("test.png")

_, peak = tracemalloc.get_traced_memory()

print(f"Memory usage peaked at {humanize.naturalsize(peak)}")

Actual outcome

Memory usage peaked at 7.2 GB

Expected outcome

Memory usage peaked at 1.7 GB

This is the result when the shebang in the code example is changed to "matplotlib<3.10", or when the fig.savefig("test.png") line is removed.

Additional information

May be related to #28904, although switching the backend to Cairo doesn't affect the results.

Operating system

Arch

Matplotlib Version

3.10.0

Matplotlib Backend

agg

Python version

Python 3.13.0

Jupyter version

No response

Installation

None

Activity

  1. zqianem
    changed the title [-][Bug]: High memory usage by `Figure.savefig` starting in version 3.10.0[/-] [+][Bug]: High memory usage by `Figure.savefig`[/+] on Jan 8, 2025
  2. zqianem
    changed the title [-][Bug]: High memory usage by `Figure.savefig`[/-] [+][Bug]: High memory usage in `Figure.savefig`[/+] on Jan 8, 2025
  3. QuLogic commented on Jan 9, 2025

    @QuLogic
    QuLogic
    on Jan 9, 2025
    Member
    More actions

    This bisects to 3ceba40; you can set image.interpolation_stage to data to avoid it switching to the rgba stage.

    Reacted by em zhan and Jody Klymak
  4. zqianem commented on Jan 9, 2025

    @zqianem
    zqianem
    on Jan 9, 2025
    Author
    More actions

    Thanks for tracking this down!

    Would it be worth adding #28061, the image resampling docs, and this workaround to the 3.10 release notes? I could see this affecting quite of bit of code with non-obvious slowdowns and OOM errors (which is how I found it in the first place 🙂).

  5. tacaswell commented on Jan 9, 2025

    @tacaswell
    tacaswell
    on Jan 9, 2025
    Member
    More actions

    Some what ironically, the big images are where the RGBA interpolation is probably the most useful.

  6. tacaswell
    added this to the v3.10.1 milestone on Jan 9, 2025
  7. tacaswell
    added
    Documentation
    on Jan 9, 2025
  8. jklymak commented on Jan 9, 2025

    @jklymak
    jklymak
    on Jan 9, 2025
    Member
    More actions

    Yeah, I'm not quite sure why that is not in the release notes. Sorry for not catching that it was missing.

    Reacted by em zhan
  9. ksunden
    modified the milestones: v3.10.1, v3.10.2 on Feb 21, 2025
  10. ksunden
    modified the milestones: v3.10.2, v3.10.3 on May 2, 2025
  11. dstansby
    added
    Performance
    on Jul 23, 2025
  12. ksunden
    modified the milestones: v3.10.4, v3.10.5 on Jul 25, 2025
  13. ksunden
    modified the milestones: v3.10.6, v3.10.7 on Aug 29, 2025
  14. ksunden
    modified the milestones: v3.10.7, v3.10.8 on Oct 8, 2025
  15. ksunden
    modified the milestones: v3.10.8, v3.10.9 on Nov 13, 2025
  16. ksunden
    removed this from the v3.10.9 milestone on May 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocumentationPerformance

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402520 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.