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>One approach is to use <code>plot</code> instead of <code>scatter</code> (you can still produce scatter plots using <code>plot</code> by using the <code>'o'</code> argument), and use the <code>rasterized</code> keyword argument, like so:</p>

<pre><code>import numpy as np 
import matplotlib.pyplot as plt

a1,b1 = np.random.randn(400000,2).T #mock data of similar size to yours
plt.plot(a1,b1,'o',rasterized=True)
plt.savefig("test.ps")
</code></pre>

<p>This should significantly reduce the size of the output file. The text and line art will remain vector, only the points are rasterized, so it is a nice compromise. </p>

<p>Depending on what you're looking to achieve, however, it might be better to histogram your data and plot that instead (e.g. <code>pyplot.hist2d</code> or <code>pyplot.hexbin</code>).</p>

python matplotlib