Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python pyplot hist中的内存错误_Python_Python 2.7_Matplotlib - Fatal编程技术网

Python pyplot hist中的内存错误

Python pyplot hist中的内存错误,python,python-2.7,matplotlib,Python,Python 2.7,Matplotlib,我的列表大小是1247746130。我想获取此列表的柱状图: bins = np.linspace(-100, 1, 100) plt.hist(refList, bins, alpha=0.5, label='reference') plt.legend(loc='upper right') plt.savefig('reference.png') 但我有一个错误: Traceback (most recent call last): File "<stdin>", line

我的列表大小是1247746130。我想获取此列表的柱状图:

bins = np.linspace(-100, 1, 100)
plt.hist(refList, bins, alpha=0.5, label='reference')
plt.legend(loc='upper right')
plt.savefig('reference.png')
但我有一个错误:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/pyplot.py", line 3081, in hist
    stacked=stacked, data=data, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/__init__.py", line 1898, in inner
    return func(ax, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/axes/_axes.py", line 6146, in hist
    x = _normalize_input(x, 'x')
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/axes/_axes.py", line 6083, in _normalize_input
    inp = np.asarray(inp)
  File "/usr/local/lib/python2.7/dist-packages/numpy/core/numeric.py", line 531, in asarray
    return array(a, dtype, copy=False, order=order)
MemoryError
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
hist中的文件“/usr/local/lib/python2.7/dist packages/matplotlib/pyplot.py”,第3081行
堆叠=堆叠,数据=数据,**kwargs)
文件“/usr/local/lib/python2.7/dist packages/matplotlib/_init__;u.py”,第1898行,在内部
返回函数(ax,*args,**kwargs)
文件“/usr/local/lib/python2.7/dist packages/matplotlib/axes/_axes.py”,第6146行,在hist中
x=_规范化_输入(x,'x')
文件“/usr/local/lib/python2.7/dist packages/matplotlib/axes/_axes.py”,第6083行,在_normalize_输入中
inp=np.asarray(inp)
asarray中的文件“/usr/local/lib/python2.7/dist packages/numpy/core/numeric.py”,第531行
返回数组(a,数据类型,copy=False,order=order)
记忆者
我有8GB内存。有没有可能得到我的数据的直方图


提前谢谢

我过去在plt.hist方面遇到过问题,所以现在使用。(尽管我认为
plt.hist
实际上在幕后使用了
numpy.histogram
)。示例如下所示:

import numpy as np
import matplotlib.pyplot as plt

bins = np.linspace(-100, 1, 100)

heights, edges = np.histogram(data, bins)
edges = edges[:-1]+(edges[1]-edges[0])

fig, ax = plt.subplots()
ax.plot(edges, heights)
plt.show()

你开始使用
plt.hist
而不是numpy了吗?@DavidG不,一点也不,我只是习惯了这个错误仍然很奇怪,
plt.hist
确实调用了
numpy.histogram
,所以不清楚为什么其中一个可以工作,而另一个不行。对我来说没有帮助。在numpy的情况下,我也会得到内存错误。我看到垃圾箱有效果