@@ -737,6 +737,7 @@ def _auto_legend_data(self):
737
737
ax = self .parent
738
738
bboxes = []
739
739
lines = []
740
+ offsets = []
740
741
741
742
for handle in ax .lines :
742
743
assert isinstance (handle , Line2D )
@@ -755,12 +756,19 @@ def _auto_legend_data(self):
755
756
transform = handle .get_transform ()
756
757
bboxes .append (handle .get_path ().get_extents (transform ))
757
758
759
+ for handle in ax .collections :
760
+ transform , transOffset , hoffsets , paths = handle ._prepare_points ()
761
+
762
+ if len (hoffsets ):
763
+ for offset in transOffset .transform (hoffsets ):
764
+ offsets .append (offset )
765
+
758
766
try :
759
767
vertices = np .concatenate ([l .vertices for l in lines ])
760
768
except ValueError :
761
769
vertices = np .array ([])
762
770
763
- return [vertices , bboxes , lines ]
771
+ return [vertices , bboxes , lines , offsets ]
764
772
765
773
def draw_frame (self , b ):
766
774
'b is a boolean. Set draw frame to b'
@@ -920,7 +928,7 @@ def _find_best_position(self, width, height, renderer, consider=None):
920
928
# should always hold because function is only called internally
921
929
assert self .isaxes
922
930
923
- verts , bboxes , lines = self ._auto_legend_data ()
931
+ verts , bboxes , lines , offsets = self ._auto_legend_data ()
924
932
925
933
bbox = Bbox .from_bounds (0 , 0 , width , height )
926
934
if consider is None :
@@ -939,6 +947,7 @@ def _find_best_position(self, width, height, renderer, consider=None):
939
947
# take their into account when checking vertex overlaps in
940
948
# the next line.
941
949
badness = legendBox .count_contains (verts )
950
+ badness += legendBox .count_contains (offsets )
942
951
badness += legendBox .count_overlaps (bboxes )
943
952
for line in lines :
944
953
# FIXME: the following line is ill-suited for lines
0 commit comments