I have ran into OverflowErrors from Matplotlib a few times. As an easy solution, I found to increase the chuncksize:
matplotlib.use('Agg')
matplotlib.rcParam['agg.path.chuncksize'] = 20000000 # 20M
For a timeseries plot with datetime index of 64k samples, I can save a figure without specifying the dpi. After a certain threshold (somewhere around dpi=260), I trigger the OverflowError.
I thought this was quite interesting cause I thought this error was only caused by too many samples in timeseries. Can anyone explain me why this is and whether this is an issue or whether I just use a too high dpi?
Python 3.9.1, Matplotlib 3.3.3, Windows 10
Edit: Code to reproduce
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)
Results for me in:
Successfully plotted without dpi
Exceeded cell block limit (set 'agg.path.chunksize' rcparam)
Process finished with exit code 0