@@ -108,7 +108,7 @@ class Legend(Artist):
108108 'upper center' : 9,
109109 'center' : 10,
110110
111- loc can be a tuple of the noramilzed coordinate values with
111+ loc can be a tuple of the normalized coordinate values with
112112 respect its parent.
113113
114114 """
@@ -736,7 +736,6 @@ def _auto_legend_data(self):
736736 assert self .isaxes
737737
738738 ax = self .parent
739- vertices = []
740739 bboxes = []
741740 lines = []
742741
@@ -757,6 +756,11 @@ def _auto_legend_data(self):
757756 transform = handle .get_transform ()
758757 bboxes .append (handle .get_path ().get_extents (transform ))
759758
759+ try :
760+ vertices = np .concatenate ([l .vertices for l in lines ])
761+ except ValueError :
762+ vertices = np .array ([])
763+
760764 return [vertices , bboxes , lines ]
761765
762766 def draw_frame (self , b ):
@@ -922,20 +926,31 @@ def _find_best_position(self, width, height, renderer, consider=None):
922926 verts , bboxes , lines = self ._auto_legend_data ()
923927
924928 bbox = Bbox .from_bounds (0 , 0 , width , height )
925- consider = [self ._get_anchored_bbox (x , bbox , self .get_bbox_to_anchor (),
926- renderer )
927- for x
928- in range (1 , len (self .codes ))]
929+ if consider is None :
930+ consider = [self ._get_anchored_bbox (x , bbox ,
931+ self .get_bbox_to_anchor (),
932+ renderer )
933+ for x in range (1 , len (self .codes ))]
929934
930935 #tx, ty = self.legendPatch.get_x(), self.legendPatch.get_y()
931936
932937 candidates = []
933938 for l , b in consider :
934939 legendBox = Bbox .from_bounds (l , b , width , height )
935940 badness = 0
941+ # XXX TODO: If markers are present, it would be good to
942+ # take their into account when checking vertex overlaps in
943+ # the next line.
936944 badness = legendBox .count_contains (verts )
937945 badness += legendBox .count_overlaps (bboxes )
938946 for line in lines :
947+ # FIXME: the following line is ill-suited for lines
948+ # that 'spiral' around the center, because the bbox
949+ # may intersect with the legend even if the line
950+ # itself doesn't. One solution would be to break up
951+ # the line into its straight-segment components, but
952+ # this may (or may not) result in a significant
953+ # slowdown if lines with many vertices are present.
939954 if line .intersects_bbox (legendBox ):
940955 badness += 1
941956
0 commit comments