39
39
import matplotlib .colors as colors
40
40
from matplotlib .font_manager import FontProperties
41
41
from matplotlib .lines import Line2D
42
- from matplotlib .patches import Patch , Rectangle , Shadow , FancyBboxPatch
42
+ from matplotlib .patches import (Patch , Rectangle , Shadow , FancyBboxPatch ,
43
+ FancyArrowPatch )
43
44
from matplotlib .collections import (LineCollection , RegularPolyCollection ,
44
45
CircleCollection , PathCollection ,
45
46
PolyCollection )
50
51
from matplotlib .offsetbox import DraggableOffsetBox
51
52
52
53
from matplotlib .container import ErrorbarContainer , BarContainer , StemContainer
54
+ from matplotlib .text import Annotation , Text
53
55
from . import legend_handler
54
56
55
57
@@ -565,7 +567,6 @@ def _set_loc(self, loc):
565
567
# value of the find_offset.
566
568
self ._loc_real = loc
567
569
self .stale = True
568
- self ._legend_box .set_offset (self ._findoffset )
569
570
570
571
def _get_loc (self ):
571
572
return self ._loc_real
@@ -649,7 +650,10 @@ def _approx_text_height(self, renderer=None):
649
650
update_func = legend_handler .update_from_first_child ),
650
651
tuple : legend_handler .HandlerTuple (),
651
652
PathCollection : legend_handler .HandlerPathCollection (),
652
- PolyCollection : legend_handler .HandlerPolyCollection ()
653
+ PolyCollection : legend_handler .HandlerPolyCollection (),
654
+ FancyArrowPatch : legend_handler .HandlerFancyArrowPatch (),
655
+ Text : legend_handler .HandlerText (),
656
+ Annotation : legend_handler .HandlerAnnotation ()
653
657
}
654
658
655
659
# (get|set|update)_default_handler_maps are public interfaces to
@@ -837,6 +841,7 @@ def _init_legend_box(self, handles, labels, markerfirst=True):
837
841
children = [self ._legend_title_box ,
838
842
self ._legend_handle_box ])
839
843
self ._legend_box .set_figure (self .figure )
844
+ self ._legend_box .set_offset (self ._findoffset )
840
845
self .texts = text_list
841
846
self .legendHandles = handle_list
842
847
@@ -1142,12 +1147,13 @@ def _get_legend_handles(axs, legend_handler_map=None):
1142
1147
handles_original = []
1143
1148
for ax in axs :
1144
1149
handles_original += (ax .lines + ax .patches +
1145
- ax .collections + ax .containers )
1150
+ ax .collections + ax .containers + ax . texts )
1146
1151
# support parasite axes:
1147
1152
if hasattr (ax , 'parasites' ):
1148
1153
for axx in ax .parasites :
1149
1154
handles_original += (axx .lines + axx .patches +
1150
- axx .collections + axx .containers )
1155
+ axx .collections + axx .containers +
1156
+ axx .texts )
1151
1157
1152
1158
handler_map = Legend .get_default_handler_map ()
1153
1159
0 commit comments