FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[Bug]: High memory usage in `Figure.savefig` · Issue #29434 · matplotlib/matplotlib · GitHub

Repository navigation

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

Description

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. 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. 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

    Member

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

  4. zqianem commented on Jan 9, 2025

    Author

    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

    Member

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

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

    Member

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

  8. modified the milestones: v3.10.1, v3.10.2 on Feb 21, 2025
  9. modified the milestones: v3.10.2, v3.10.3 on May 2, 2025
  10. modified the milestones: v3.10.4, v3.10.5 on Jul 25, 2025
  11. modified the milestones: v3.10.6, v3.10.7 on Aug 29, 2025
  12. modified the milestones: v3.10.7, v3.10.8 on Oct 8, 2025
  13. modified the milestones: v3.10.8, v3.10.9 on Nov 13, 2025
  14. 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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL