python runtime_error ai_generated true

RuntimeError: 图像尺寸 100000x80000 像素过大。每个方向必须小于 2^16。

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

其他格式: JSON · Markdown 中文 · English
80%修复率
86%置信度
0证据数
2024-11-28首次发现

版本兼容性

版本状态引入弃用备注
3.x active — — —

根因分析

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

English

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

generic

解决方案

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

无效尝试

常见但无效的做法:

  1. 92% 失败

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

  2. 85% 失败

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