python - Getting Memory Error when trying to plot large array with matplotlib -
I would like to plot an array of 20 million objects, I have 8 GB RAM and even when I run I get the following error: The following lines:
import matlotlib.pyplot as plt import numpy np d = np.arange (200000000) plt.plot (d) plt.show () < / Code> error:
traceback (most recent call final): ... file "C: \ Python 27 \ lib \ site-packages \ matplotlib \ Axes.py ", line 317, in self _grab_next_args for segment (remaining, queue C): File "C: \ Python27 \ lib \ site-packages \ matplotlib \ axes.py", line 292, _plot_args x = np.arange (y.shape [0], DEPIP = float) MemoryArror < Due to the physical limitations of the display and plotters, you will not be able to plot 20,000,000 anyway.
You can reduce your array by sampling it or using a slice:
& gt; & Gt; & Gt; Me = 20000000 & gt; & Gt; & Gt; A = np.arange (m)> gt; & Gt; & Gt; N = 100 # & lt; - Reduce to 100 points & gt; & Gt; & Gt; S = m / n # & lt; - To compress the size of the slides, click & gt; & Gt; & Gt; Less = []> & Gt; & Gt; I am in the xrange (n): ... piece = one [i * s: (i + 1) * s] ... less .append (np.mean (piece)) gt; & Gt; & Gt; Low [99 99.5, 2999 99, 5, ..., 1969 99 99, 59, 99 99, 95] .. Suppose Np.mean is understandable on items you are going to plot.
Comments
Post a Comment