title: Plotting a large number of points using matplotlib and running out of memory
body: <p>I have a large (~6GB) text file in a simple format</p>
  
  <pre><code>x1 y1 z1
  x2 y2 z2
  ...
  </code></pre>
  
  <p>Since I may load this data more than once, I've created a <code>np.memmap</code> file for efficiency reasons: </p>
  
  <pre><code>X,Y,Z = np.memmap(f_np_mmap,dtype='float32',mode='r',shape=shape).T
  </code></pre>
  
  <p>What I'm trying to do is plot:</p>
  
  <pre><code>plt.scatter(X, Y, 
             color=custom_colorfunction(Z), 
             alpha=.01, s=.001, marker='s', linewidth=0)
  </code></pre>
  
  <p>This works perfectly for smaller datasets. However, for this larger dataset I run out of memory. I've checked that <code>plt.scatter</code> is taking all the memory; I can step through <code>X,Y,Z</code> just fine. Is there a way I "rasterize" the canvas so I do not run out of memory? I do not need to zoom and pan around the image, it is going straight to disk. I realize that I can bin the data and plot that, but I'm not sure how to do this with a custom colormap <em>and</em> an alpha value.</p>