8000 Don't bother concatenating vertices in _auto_legend_data. · matplotlib/matplotlib@48ec134 · GitHub
[go: up one dir, main page]

Skip to content

Commit 48ec134

Browse files
committed
Don't bother concatenating vertices in _auto_legend_data.
1 parent f052d1e commit 48ec134

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

lib/matplotlib/legend.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -828,8 +828,6 @@ def _auto_legend_data(self):
828828
829829
Returns
830830
-------
831-
vertices
832-
List of (x, y) vertices of all lines.
833831
bboxes
834832
List of bounding boxes of all patches.
835833
lines
@@ -841,7 +839,6 @@ def _auto_legend_data(self):
841839
ax = self.parent
842840
lines = [line.get_transform().transform_path(line.get_path())
843841
for line in ax.lines]
844-
vertices = np.concatenate([l.vertices for l in lines]) if lines else []
845842
bboxes = [patch.get_bbox().transformed(patch.get_data_transform())
846843
if isinstance(patch, Rectangle) else
847844
patch.get_path().get_extents(patch.get_transform())
@@ -851,7 +848,7 @@ def _auto_legend_data(self):
851848
_, transOffset, hoffsets, _ = handle._prepare_points()
852849
for offset in transOffset.transform(hoffsets):
853850
offsets.append(offset)
854-
return vertices, bboxes, lines, offsets
851+
return bboxes, lines, offsets
855852

856853
def get_children(self):
857854
"""Return the list of child artists."""
@@ -1031,7 +1028,7 @@ def _find_best_position(self, width, height, renderer, consider=None):
10311028

10321029
start_time = time.perf_counter()
10331030

1034-
verts, bboxes, lines, offsets = self._auto_legend_data()
1031+
bboxes, lines, offsets = self._auto_legend_data()
10351032

10361033
bbox = Bbox.from_bounds(0, 0, width, height)
10371034
if consider is None:
@@ -1046,7 +1043,8 @@ def _find_best_position(self, width, height, renderer, consider=None):
10461043
badness = 0
10471044
# XXX TODO: If markers are present, it would be good to take them
10481045
# into account when checking vertex overlaps in the next line.
1049-
badness = (legendBox.count_contains(verts)
1046+
badness = (sum(legendBox.count_contains(line.vertices)
1047+
for line in lines)
10501048
+ legendBox.count_contains(offsets)
10511049
+ legendBox.count_overlaps(bboxes)
10521050
+ sum(line.intersects_bbox(legendBox, filled=False)

0 commit comments

Comments
 (0)
0