溢出错误图 [英] overflow error Plot

查看:54
本文介绍了溢出错误图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做一些声音/音频和音乐处理工作.在此之前,我创建了一个 10 秒扫描的样本信号.我有一个简单的脚本,它必须绘制一些信号.第一个信号是一个简单的正弦;扫一扫;两者的频率都低于奈奎斯特频率,所以没问题.

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.

代码:

#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()

当我运行 Python 代码时,它使用简单的正弦波运行良好,但不适用于扫描.

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

它给出了以下错误:

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

将频率 f1 更改为采样频率的10%左右时,我没有任何错误.但是我想在CD音频范围内创建一些扫描,以便了解发生了什么以及如何避免此问题

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

我在Windows/Ubuntu上将Spyder与IPython一起使用.

I use Spyder with IPython on Windows/ Ubuntu.

编辑 2:我知道屏幕分辨率不够好……但 GNU 八度/matlab/……它运行良好.具有相同样本数量的简单正弦波工作正常......所以它对数据点的反应不同......

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...

推荐答案

感谢@ali_m和他的链接,我找到了解决方法.

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

根据答案,我需要将10 000至100 000的 agg.path.chunksize 添加.因为我不想在 matplotlibrc 文件中执行此操作,所以我必须在脚本中执行此操作.

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.

根据关于自己的 github 的讨论,我找到了执行此操作的正确方法.我必须在脚本中添加 plt.rcParams ['agg.path.chunksize'] = 10000 ,现在可以正常使用了.

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.

这篇关于溢出错误图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆