2017-06-02 130 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