使用matplotlib绘图时出现内存错误

时间:2016-09-20 22:03:34

标签: python-2.7 matplotlib

尝试使用matplotlib绘制pandas Dataframe。但它抱怨内存错误。需要帮助解决问题。

Dataframe的大小:[1835行x 1列] 相同大小的Numpy数组。

代码类似于以下内容。

import pandas as pd
import matplotlib.pyplot as plt
import numpy as np

sorted_values = data['values'].sort_values()   # data['values'] is of size 1835 rows x 1 columns
forc = np.array(range(1835), float)
plt.plot(sorted_values, forc, marker='o', ms=3.0, lw=1.5)

但matplotlib抱怨记忆。

File "C:\Anaconda2\lib\site-packages\IPython\core\formatters.py", line 339, in __call__
return printer(obj)

File "C:\Anaconda2\lib\site-packages\IPython\core\pylabtools.py", line 228, in <lambda>
png_formatter.for_type(Figure, lambda fig: print_figure(fig, 'png', **kwargs))

File "C:\Anaconda2\lib\site-packages\IPython\core\pylabtools.py", line 119, in print_figure
fig.canvas.print_figure(bytes_io, **kw)

File "C:\Anaconda2\lib\site-packages\matplotlib\backend_bases.py", line 2151, in print_figure
self.figure.dpi = dpi

File "C:\Anaconda2\lib\site-packages\matplotlib\figure.py", line 410, in _set_dpi
self.dpi_scale_trans.clear().scale(dpi, dpi)

File "C:\Anaconda2\lib\site-packages\matplotlib\transforms.py", line 1885, in clear
self.invalidate()

File "C:\Anaconda2\lib\site-packages\matplotlib\transforms.py", line 136, in invalidate
return self._invalidate_internal(value, invalidating_node=self)

File "C:\Anaconda2\lib\site-packages\matplotlib\transforms.py", line 158, in _invalidate_internal
for parent in list(six.itervalues(self._parents)):

MemoryError

1 个答案:

答案 0 :(得分:0)

我能够通过在绘图时删除标记(和标记化)来解决自己。

基本上,在绘制较大数据时请避免使用标记。