matplotlib/matplotlib — pull request #2423 by mdboom (2013-10-01 22:14:23+00:00)
Title: Off-axes markers unnecessarily saved to PDF

Plotting a bunch of markers without lines, then changing the axes limits so none of the points are visible, and then saving the result to a PDF, results in a file just as big as if the markers were all visible within their default axes limits. This doesn't happen for line only plots.

I guess the PDF backend clips the lines before deciding what to save to file, but it doesn't clip the markers. Not only does this result in an unnecessarily large PDF file (and potentially a security issue, because data is unintentionally leaking out), but rendering that file in a PDF viewer can be a lot slower as well.

Here's some demo code:

```python
import numpy as np
x = np.random.random(20000)
y = np.random.random(20000)

figure()
plot(x, y, 'k.') # use markers only
pyplot.savefig('dots.pdf')
xlim(2, 3) # move axes away for empty plot
pyplot.savefig('dots_empty.pdf')
'''
file sizes in bytes:
dots.pdf: 327505
dots_empty.pdf: 327921
'''
figure()
plot(x, y, 'k-') # use lines only
pyplot.savefig('lines.pdf')
xlim(2, 3) # move axes away for empty plot
pyplot.savefig('lines_empty.pdf')
'''
file sizes in bytes:
lines.pdf: 310071
lines_empty.pdf: 5905
'''
```