Skip to content

fig.savefig gives OverflowError for high DPI's #19325

@nielsuit227

Description

@nielsuit227

Bug report

Even with short timeseries, fig.savefig() throws an OverflowError for high dpi's.
The example below uses 'Agg' with a significantly increased chunksize, yet it still throws an error for dpis > 250.

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

matplotlib.use('Agg')
matplotlib.rcParams['agg.path.chunksize'] = 20000000

x = np.linspace(0, 100, 100000)
y = np.random.randint(1, 100, 100000)

fig = plt.figure()
plt.plot(x, y)

try:
    fig.savefig('Figure.png', format='png')
    print('Successfully plotted without dpi')
except Exception as e:
    print(e)
try:
    fig.savefig('Figure.png', format='png', dpi=500)
    print('Successfully plotted with high dpi')
except Exception as e:
    print(e)

The output here is:

Successfully plotted without dpi
Exceeded cell block limit (set 'agg.path.chunksize' rcparam)

Process finished with exit code 0

whereas I expected both to be successfully plotted, given that the chunksize OverflowError should only show when the number of plots exceeds the chunksize.

Matplotlib version

  • Operating system: Windows 10
  • Matplotlib version: 3.3.3
  • Matplotlib backend: agg
  • Python version: 3..9.1
  • Other libraries: NumPy 1.19.4
  • Everything is installed with pip

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions