Skip to content

Commit 3d38633

Browse files
committed
Use the uses_per_path data in pdf backend
Fixes matplotlib#3345
1 parent 07a58af commit 3d38633

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

lib/matplotlib/backends/backend_pdf.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1622,7 +1622,17 @@ def draw_path_collection(self, gc, master_transform, paths, all_transforms,
16221622
else:
16231623
can_do_optimization = False
16241624

1625-
if not can_do_optimization:
1625+
# Is the optimization worth it? Rough calculation:
1626+
# cost of emitting a path in-line is len_path * uses_per_path
1627+
# cost of XObject is len_path + 5 for the definition,
1628+
# uses_per_path for the uses
1629+
len_path = len(paths[0].vertices) if len(paths) > 0 else 0
1630+
uses_per_path = self._iter_collection_uses_per_path(
1631+
paths, all_transforms, offsets, facecolors, edgecolors)
1632+
should_do_optimization = \
1633+
len_path + uses_per_path + 5 < len_path * uses_per_path
1634+
1635+
if (not can_do_optimization) or (not should_do_optimization):
16261636
return RendererBase.draw_path_collection(
16271637
self, gc, master_transform, paths, all_transforms,
16281638
offsets, offsetTrans, facecolors, edgecolors,
@@ -1654,9 +1664,10 @@ def draw_path_collection(self, gc, master_transform, paths, all_transforms,
16541664

16551665
def draw_markers(self, gc, marker_path, marker_trans, path, trans,
16561666
rgbFace=None):
1657-
# For simple paths or small numbers of markers, don't bother
1658-
# making an XObject
1659-
if len(path) * len(marker_path) <= 10:
1667+
# Same logic as in draw_path_collection
1668+
len_marker_path = len(marker_path)
1669+
uses = len(path)
1670+
if len_marker_path * uses < len_marker_path + uses + 5:
16601671
RendererBase.draw_markers(self, gc, marker_path, marker_trans,
16611672
path, trans, rgbFace)
16621673
return

0 commit comments

Comments
 (0)