python runtime_error ai_generated true

RuntimeError: In set_size: Could not set the fontsize (or) Image size of 100000x80000 pixels is too large. It must be less than 2^16 in each direction.

ID: python/matplotlib-figure-too-large

Also available as: JSON · Markdown · 中文
80%Fix Rate
86%Confidence
0Evidence
2024-11-28First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
3.x active — — —

Root Cause

Saving a figure with figsize*dpi exceeding 65535 pixels in either dimension, which exceeds the PNG/JPEG limits enforced by the backend.

generic

中文

保存图形时 figsize*dpi 在任一维度超过 65535 像素,超出后端对 PNG/JPEG 的限制。

Workarounds

  1. 95% success
    fig.set_size_inches(20, 16)
    fig.savefig('out.png', dpi=150)  # 3000x2400 px
  2. 92% success
    fig.savefig('out.pdf')  # no pixel limit for vector backends

Dead Ends

Common approaches that don't work:

  1. 92% fail

    Higher dpi worsens the pixel count and triggers the same limit.

  2. 85% fail

    'raw' is not a valid format for savefig; the size limit still applies to raster backends.