Reducing file size of scatter plot
<p>I am currently trying to reduce the file size of a scatter plot. My code looks like:</p>

<pre><code>plt.scatter(a1,b1)
plt.savefig('test.ps')
</code></pre>

<p>where a1,b1 are arrays of size 400,000 or so, and it gives a file size of 7.8MB.</p>

<p>I have tried adding </p>

<pre><code>plt.rcParams['path.simplify'] = True
</code></pre>

<p>before this chunk of code, but the file is still 7.8MB. Is this an issue with how it saves as a ".ps" file or another issue?</p>

<p>You could consider using e.g. <code>hexbin</code> -- I particularly like this when you have a dense collection of points, since it better indicates where your data is concentrated. For example:</p>

<pre><code>import numpy as np
import matplotlib.pylab as pl

x = np.random.normal(size=40000)
y = np.random.normal(size=40000)

pl.figure()

pl.subplot(121)
pl.scatter(x, y)
pl.xlim(-4,4)
pl.ylim(-4,4)

pl.subplot(122)
pl.hexbin(x, y, gridsize=40)
pl.xlim(-4,4)
pl.ylim(-4,4)
</code></pre>

<p><a href="https://i.stack.imgur.com/3SXJS.png" rel="nofollow"><img src="https://i.stack.imgur.com/3SXJS.png" alt="enter image description here"></a></p>

<p>From the left figure, I would have concluded that the distribution of points between <code>x,y = {-3,3}</code> is roughly equal, which clearly is not the case. </p>

<p>(<a href="http://matplotlib.org/examples/pylab_examples/hexbin_demo.html" rel="nofollow">http://matplotlib.org/examples/pylab_examples/hexbin_demo.html</a>)</p>

python matplotlib