@@ -828,8 +828,6 @@ def _auto_legend_data(self):
828
828
829
829
Returns
830
830
-------
831
- vertices
832
- List of (x, y) vertices of all lines.
833
831
bboxes
834
832
List of bounding boxes of all patches.
835
833
lines
@@ -841,7 +839,6 @@ def _auto_legend_data(self):
841
839
ax = self .parent
842
840
lines = [line .get_transform ().transform_path (line .get_path ())
843
841
for line in ax .lines ]
844
- vertices = np .concatenate ([l .vertices for l in lines ]) if lines else []
845
842
bboxes = [patch .get_bbox ().transformed (patch .get_data_transform ())
846
843
if isinstance (patch , Rectangle ) else
847
844
patch .get_path ().get_extents (patch .get_transform ())
@@ -851,7 +848,7 @@ def _auto_legend_data(self):
851
848
_ , transOffset , hoffsets , _ = handle ._prepare_points ()
852
849
for offset in transOffset .transform (hoffsets ):
853
850
offsets .append (offset )
854
- return vertices , bboxes , lines , offsets
851
+ return bboxes , lines , offsets
855
852
856
853
def get_children (self ):
857
854
"""Return the list of child artists."""
@@ -1031,7 +1028,7 @@ def _find_best_position(self, width, height, renderer, consider=None):
1031
1028
1032
1029
start_time = time .perf_counter ()
1033
1030
1034
- verts , bboxes , lines , offsets = self ._auto_legend_data ()
1031
+ bboxes , lines , offsets = self ._auto_legend_data ()
1035
1032
1036
1033
bbox = Bbox .from_bounds (0 , 0 , width , height )
1037
1034
if consider is None :
@@ -1046,7 +1043,8 @@ def _find_best_position(self, width, height, renderer, consider=None):
1046
1043
badness = 0
1047
1044
# XXX TODO: If markers are present, it would be good to take them
1048
1045
# 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 )
1050
1048
+ legendBox .count_contains (offsets )
1051
1049
+ legendBox .count_overlaps (bboxes )
1052
1050
+ sum (line .intersects_bbox (legendBox , filled = False )
0 commit comments