Skip to content

Commit 3516356

Browse files
committed
Ensure legend(loc='best') warning is always triggered
If a candidate location was picked, then that would be returned directly without warning even if it took just as long.
1 parent 6dfdc02 commit 3516356

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

lib/matplotlib/legend.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,7 +1174,6 @@ def _find_best_position(self, width, height, renderer):
11741174
self.get_bbox_to_anchor(),
11751175
renderer)
11761176
legendBox = Bbox.from_bounds(l, b, width, height)
1177-
badness = 0
11781177
# XXX TODO: If markers are present, it would be good to take them
11791178
# into account when checking vertex overlaps in the next line.
11801179
badness = (sum(legendBox.count_contains(line.vertices)
@@ -1183,10 +1182,10 @@ def _find_best_position(self, width, height, renderer):
11831182
+ legendBox.count_overlaps(bboxes)
11841183
+ sum(line.intersects_bbox(legendBox, filled=False)
11851184
for line in lines))
1186-
if badness == 0:
1187-
return l, b
11881185
# Include the index to favor lower codes in case of a tie.
11891186
candidates.append((badness, idx, (l, b)))
1187+
if badness == 0:
1188+
break
11901189

11911190
_, _, (l, b) = min(candidates)
11921191

0 commit comments

Comments
 (0)