2017-06-02 128 views
0

我有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 

我有8GB的内存。是否有可能为我的数据获取直方图?

在此先感谢!

+0

您是否使用'plt.hist'而不是numpy? – DavidG

+0

@DavidG不,一点都不习惯,我刚刚习惯了 – user2080209

+0

这个错误仍然很奇怪,'plt.hist'确实调用'numpy.histogram',所以目前还不清楚为什么其中一个应该工作而不是另一个。 – ImportanceOfBeingErnest

回答

1

我以前在plt.hist有问题,所以现在用numpy.histogram。 (尽管我认为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() 
+0

帮助,非常感谢! – user2080209

+0

没问题:)如果有效,请不要忘记接受答案。 – DavidG