@@ -737,6 +737,7 @@ def _auto_legend_data(self):
737737 ax = self .parent
738738 bboxes = []
739739 lines = []
740+ offsets = []
740741
741742 for handle in ax .lines :
742743 assert isinstance (handle , Line2D )
@@ -755,12 +756,19 @@ def _auto_legend_data(self):
755756 transform = handle .get_transform ()
756757 bboxes .append (handle .get_path ().get_extents (transform ))
757758
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+
758766 try :
759767 vertices = np .concatenate ([l .vertices for l in lines ])
760768 except ValueError :
761769 vertices = np .array ([])
762770
763- return [vertices , bboxes , lines ]
771+ return [vertices , bboxes , lines , offsets ]
764772
765773 def draw_frame (self , b ):
766774 'b is a boolean. Set draw frame to b'
@@ -920,7 +928,7 @@ def _find_best_position(self, width, height, renderer, consider=None):
920928 # should always hold because function is only called internally
921929 assert self .isaxes
922930
923- verts , bboxes , lines = self ._auto_legend_data ()
931+ verts , bboxes , lines , offsets = self ._auto_legend_data ()
924932
925933 bbox = Bbox .from_bounds (0 , 0 , width , height )
926934 if consider is None :
@@ -939,6 +947,7 @@ def _find_best_position(self, width, height, renderer, consider=None):
939947 # take their into account when checking vertex overlaps in
940948 # the next line.
941949 badness = legendBox .count_contains (verts )
950+ badness += legendBox .count_contains (offsets )
942951 badness += legendBox .count_overlaps (bboxes )
943952 for line in lines :
944953 # FIXME: the following line is ill-suited for lines
0 commit comments