Skip to content

Off-axes markers unnecessarily saved to PDF #2423

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 9, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion lib/matplotlib/backends/backend_pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -1615,9 +1615,17 @@ def draw_markers(self, gc, marker_path, marker_trans, path, trans, rgbFace=None)

output(Op.gsave)
lastx, lasty = 0, 0
for vertices, code in path.iter_segments(trans, simplify=False):
for vertices, code in path.iter_segments(
trans,
clip=(0, 0, self.file.width*72, self.file.height*72),
simplify=False):
if len(vertices):
x, y = vertices[-2:]
if (x < 0 or
y < 0 or
x > self.file.width * 72 or
y > self.file.height * 72):
continue
dx, dy = x - lastx, y - lasty
output(1, 0, 0, 1, dx, dy, Op.concat_matrix,
marker, Op.use_xobject)
Expand Down
5 changes: 4 additions & 1 deletion lib/matplotlib/backends/backend_ps.py
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,10 @@ def draw_markers(self, gc, marker_path, marker_trans, path, trans, rgbFace=None)
ps_cmd.append('stroke')
ps_cmd.extend(['grestore', '} bind def'])

for vertices, code in path.iter_segments(trans, simplify=False):
for vertices, code in path.iter_segments(
trans,
clip=(0, 0, self.width*72, self.height*72),
simplify=False):
if len(vertices):
x, y = vertices[-2:]
ps_cmd.append("%g %g o" % (x, y))
Expand Down
4 changes: 3 additions & 1 deletion lib/matplotlib/backends/backend_svg.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,9 @@ def draw_markers(self, gc, marker_path, marker_trans, path, trans, rgbFace=None)

trans_and_flip = self._make_flip_transform(trans)
attrib = {'xlink:href': '#%s' % oid}
for vertices, code in path.iter_segments(trans_and_flip, simplify=False):
clip = (0, 0, self.width*72, self.height*72)
for vertices, code in path.iter_segments(
trans_and_flip, clip=clip, simplify=False):
if len(vertices):
x, y = vertices[-2:]
attrib['x'] = six.text_type(x)
Expand Down
18 changes: 16 additions & 2 deletions lib/matplotlib/tests/test_backend_pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ def test_type42():
@cleanup
def test_multipage_pagecount():
from matplotlib.backends.backend_pdf import PdfPages
from io import BytesIO
with PdfPages(BytesIO()) as pdf:
with PdfPages(io.BytesIO()) as pdf:
assert pdf.get_pagecount() == 0
fig = plt.figure()
ax = fig.add_subplot(111)
Expand All @@ -53,6 +52,21 @@ def test_multipage_pagecount():
assert pdf.get_pagecount() == 2


@cleanup
def test_cull_markers():
x = np.random.random(20000)
y = np.random.random(20000)

fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(x, y, 'k.')
ax.set_xlim(2, 3)

pdf = io.BytesIO()
fig.savefig(pdf, format="pdf")
assert len(pdf.getvalue()) < 8000
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems reasonable. Is there a similar we can apply to test svg and ps?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. We probably should.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did this get done?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No -- sorry to be off the radar for so long. I'll look into this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I merged in the knowledge that this didn't get done. It wasn't a blocker so was happier moving things forwards rather than holding it up.

@mdboom - hope you and the family are feeling better now.



@cleanup
def test_multipage_keep_empty():
from matplotlib.backends.backend_pdf import PdfPages
Expand Down