overflow error Plot

假装没事ソ 提交于 2021-01-27 12:15:51

问题


I want do stuff with sound/ audio and music processing. Before this i created a sample signal with a 10 second sweep. I have a simple script which have to plot some signals. First signal is a simple sine; second a sweep; Both with frequency just below Nyquist frequency so thats no problem.

The Code:

#import
import numpy as np
import scipy.signal as sig
import matplotlib.pylab as plt

f0 = 50
f1 = 20000 
t1 = 10
t = np.arange(0,t1,1/44100)#[numpy.newaxis]; 
print(t.shape)

sine = np.sin(2*np.pi*f0*t)

plt.plot(t, sine)
plt.xlabel('Angle [rad]')
plt.ylabel('sin(t)')
plt.axis('tight')
plt.show()

sweep = sig.chirp(t,f0,t1,f1,'linear',90) 

plt.plot(t, sweep)
plt.xlabel('Angle [rad]')
plt.ylabel('sin(t)')
plt.axis('tight')
plt.show()

When I run the Python code it runs fine with the simple sine wave, but not with the sweep.

It gave the following error(s):

runfile('C:/Users/****/Documents/python/test_sweep.py', wdir='C:/Users/****/Documents/python')
(441000,)

Traceback (most recent call last):

File "C:\Users\****\Documents\python\WinPython-64bit-3.4.3.5\python-3.4.3.amd64\lib\site-packages\IPython\core\formatters.py", line 330, in __call__
return printer(obj)

File "C:\Users\****\Documents\python\WinPython-64bit-3.4.3.5\python-3.4.3.amd64\lib\site-packages\IPython\core\pylabtools.py", line 207, in <lambda>
png_formatter.for_type(Figure, lambda fig: print_figure(fig, 'png', **kwargs))

File "C:\Users\****\Documents\python\WinPython-64bit-3.4.3.5\python-3.4.3.amd64\lib\site-packages\IPython\core\pylabtools.py", line 117, in print_figure
fig.canvas.print_figure(bytes_io, **kw)

File "C:\Users\****\Documents\python\WinPython-64bit-3.4.3.5\python-3.4.3.amd64\lib\site-packages\matplotlib\backend_bases.py", line 2158, in print_figure
**kwargs)

File "C:\Users\****\Documents\python\WinPython-64bit-3.4.3.5\python-3.4.3.amd64\lib\site-packages\matplotlib\backends\backend_agg.py", line 521, in print_png
FigureCanvasAgg.draw(self)

File "C:\Users\****\Documents\python\WinPython-64bit-3.4.3.5\python-3.4.3.amd64\lib\site-packages\matplotlib\backends\backend_agg.py", line 469, in draw
self.figure.draw(self.renderer)

File "C:\Users\****\Documents\python\WinPython-64bit-3.4.3.5\python-3.4.3.amd64\lib\site-packages\matplotlib\artist.py", line 59, in draw_wrapper
draw(artist, renderer, *args, **kwargs)

File "C:\Users\****\Documents\python\WinPython-64bit-3.4.3.5\python-3.4.3.amd64\lib\site-packages\matplotlib\figure.py", line 1085, in draw
func(*args)

File "C:\Users\****\Documents\python\WinPython-64bit-3.4.3.5\python-3.4.3.amd64\lib\site-packages\matplotlib\artist.py", line 59, in draw_wrapper
draw(artist, renderer, *args, **kwargs)

File "C:\Users\****\Documents\python\WinPython-64bit-3.4.3.5\python-3.4.3.amd64\lib\site-packages\matplotlib\axes\_base.py", line 2110, in draw
a.draw(renderer)

File "C:\Users\****\Documents\python\WinPython-64bit-3.4.3.5\python-3.4.3.amd64\lib\site-packages\matplotlib\artist.py", line 59, in draw_wrapper
draw(artist, renderer, *args, **kwargs)

File "C:\Users\****\Documents\python\WinPython-64bit-3.4.3.5\python-3.4.3.amd64\lib\site-packages\matplotlib\lines.py", line 715, in draw
drawFunc(renderer, gc, tpath, affine.frozen())

File "C:\Users\****\Documents\python\WinPython-64bit-3.4.3.5\python-3.4.3.amd64\lib\site-packages\matplotlib\lines.py", line 1072, in _draw_lines
self._lineFunc(renderer, gc, path, trans)

File "C:\Users\****\Documents\python\WinPython-64bit-3.4.3.5\python-3.4.3.amd64\lib\site-packages\matplotlib\lines.py", line 1112, in _draw_solid
renderer.draw_path(gc, path, trans)

File "C:\Users\****\Documents\python\WinPython-64bit-3.4.3.5\python-3.4.3.amd64\lib\site-packages\matplotlib\backends\backend_agg.py", line 163, in draw_path
self._renderer.draw_path(gc, path, transform, rgbFace)

OverflowError: Allocated too many blocks

When Changing the frequency f1 to around 10% of the sample frequency i don't have any errors. But i wanna create some sweeps within the CD audio range so what's happent and how to avoid this problem

Edit: I use Spyder with IPython on Windows/ Ubuntu.

edit 2: I know that the screen resolution is not fine enough... but otherwise GNU octave/ matlab/ ... it work well. the simple sinewave with the same number of samples works fine... so it the different in reaction on data points...


回答1:


Thanks to the commend of @ali_m and his link i found a solution.

according to the answer there i need to add agg.path.chunksize of 10 000 to 100 000. because i don't want to do that in the matplotlibrc file i had to do that in the script.

According to a discusion on there own github i found the right method doing that. I have to add plt.rcParams['agg.path.chunksize'] = 10000 to the script and now it works fine.




回答2:


This worked for me too, on a Windows 7 Professional workstation, Python 3.8.4.

plt rcParams['agg.path.chunksize'] = 10000

My dataset has 67m observations.



来源:https://stackoverflow.com/questions/34490250/overflow-error-plot

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!