@@ -108,7 +108,7 @@ class Legend(Artist):
108
108
'upper center' : 9,
109
109
'center' : 10,
110
110
111
- loc can be a tuple of the noramilzed coordinate values with
111
+ loc can be a tuple of the normalized coordinate values with
112
112
respect its parent.
113
113
114
114
"""
@@ -736,7 +736,6 @@ def _auto_legend_data(self):
736
736
assert self .isaxes
737
737
738
738
ax = self .parent
739
- vertices = []
740
739
bboxes = []
741
740
lines = []
742
741
@@ -757,6 +756,11 @@ def _auto_legend_data(self):
757
756
transform = handle .get_transform ()
758
757
bboxes .append (handle .get_path ().get_extents (transform ))
759
758
759
+ try :
760
+ vertices = np .concatenate ([l .vertices for l in lines ])
761
+ except ValueError :
762
+ vertices = np .array ([])
763
+
760
764
return [vertices , bboxes , lines ]
761
765
762
766
def draw_frame (self , b ):
@@ -922,20 +926,31 @@ def _find_best_position(self, width, height, renderer, consider=None):
922
926
verts , bboxes , lines = self ._auto_legend_data ()
923
927
924
928
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 ))]
929
934
930
935
#tx, ty = self.legendPatch.get_x(), self.legendPatch.get_y()
931
936
932
937
candidates = []
933
938
for l , b in consider :
934
939
legendBox = Bbox .from_bounds (l , b , width , height )
935
940
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.
936
944
badness = legendBox .count_contains (verts )
937
945
badness += legendBox .count_overlaps (bboxes )
938
946
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.
939
954
if line .intersects_bbox (legendBox ):
940
955
badness += 1
941
956
0 commit comments