gpt4 book ai didi

matlab - 在 Python 中使用 matplotlib 绘制多个数据点

转载 作者:太空宇宙 更新时间:2023-11-03 19:45:48 27 4
gpt4 key购买 nike

我最近从 MATLAB 切换到 Python 进行数据分析,我正在使用 matplotlib 进行数据可视化。如果我想可视化的数据点数量很少,这很好用。但是,如果我想想象一下,例如

import matplotlib.pyplot as plt
signal = [round(random.random() * 100) for i in xrange(0, 1000000)]
plt.plot(signal)
plt.show()

我收到一个错误:

Exception in Tkinter callback
Traceback (most recent call last):
File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1489, in __call__
return self.func(*args)
File "/usr/lib/pymodules/python2.7/matplotlib/backends/backend_tkagg.py", line 276, in resize
self.show()
File "/usr/lib/pymodules/python2.7/matplotlib/backends/backend_tkagg.py", line 348, in draw
FigureCanvasAgg.draw(self)
File "/usr/lib/pymodules/python2.7/matplotlib/backends/backend_agg.py", line 451, in draw
self.figure.draw(self.renderer)
File "/usr/lib/pymodules/python2.7/matplotlib/artist.py", line 55, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "/usr/lib/pymodules/python2.7/matplotlib/figure.py", line 1034, in draw
func(*args)
File "/usr/lib/pymodules/python2.7/matplotlib/artist.py", line 55, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "/usr/lib/pymodules/python2.7/matplotlib/axes.py", line 2086, in draw
a.draw(renderer)
File "/usr/lib/pymodules/python2.7/matplotlib/artist.py", line 55, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "/usr/lib/pymodules/python2.7/matplotlib/lines.py", line 562, in draw
drawFunc(renderer, gc, tpath, affine.frozen())
File "/usr/lib/pymodules/python2.7/matplotlib/lines.py", line 938, in _draw_lines
self._lineFunc(renderer, gc, path, trans)
File "/usr/lib/pymodules/python2.7/matplotlib/lines.py", line 978, in _draw_solid
renderer.draw_path(gc, path, trans)
File "/usr/lib/pymodules/python2.7/matplotlib/backends/backend_agg.py", line 145, in draw_path
self._renderer.draw_path(gc, path, transform, rgbFace)
OverflowError: Allocated too many blocks

你能告诉我在这种情况下你会怎么做吗?你在降低数据采样率吗?如果我在 MATLAB 中执行相同的绘图,即使有更多的数据点,我以前也没有遇到过这个问题。

最佳答案

不确定您要显示的确切内容,但您可以将情节更改为 '.',它会起作用。

import random
import pylab as plt
signal = [round(random.random() * 100) for i in xrange(0, 1000000)]
plt.plot(signal, '.')
plt.show()

您可以通过使用 matlotlibrc 文件进行自定义来获得所需的内容,文档为 here

关于matlab - 在 Python 中使用 matplotlib 绘制多个数据点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23870186/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com