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>I would think that this is due to the PostScript format, and nothing that can be changed. Let's do the math:</p>

<p>7.8MB is something like 7.8 * 1024 * 1024 = 8,178,892.8. Assuming that you have 400,000 points in your scatter plot, that means that your file would assign something like 20 bytes to each point in your scatterplot if there was nothing else in your file (i.e. no legends, no annotations etc). </p>

<p>Now, I'm not a PostScript expert, but looking at the output <code>test.ps</code>, the command used to draw circles in PostScript looks like this:</p>

<pre><code>[x] [y] o
</code></pre>

<p>where x and y are the coordinates of each point. As these are float values, the information does indeed add up to 15 bytes, which is not too far off my guess above.</p>

<p>So yes, the file size is caused by the nature of the PostScript file, which stores quite a bit of information for each of the 400,000 points in your scatterplot. </p>

<p>You can store the scatterplot as a rasterized image as suggested in @AngusWilliams' answer, and this will result in a smaller file size. However, you will lose the advantage of a vector-based file format: lossless scaling at any resolution. </p>

<p>If you don't need this advantages of vector-based file formats, you may be better off with even another file format like <code>.png</code> which does usually a much better job in compressing the image than PostScript containing rasterized information.</p>

python matplotlib