Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4c2e1d6

Browse files
author
Travis CI
committed
Add legend handler and artist for FancyArrow (clean commit)
1 parent 91bc843 commit 4c2e1d6

File tree

4 files changed

+296
-25
lines changed

4 files changed

+296
-25
lines changed

lib/matplotlib/legend.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@
3939
import matplotlib.colors as colors
4040
from matplotlib.font_manager import FontProperties
4141
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)
4344
from matplotlib.collections import (LineCollection, RegularPolyCollection,
4445
CircleCollection, PathCollection,
4546
PolyCollection)
@@ -50,6 +51,7 @@
5051
from matplotlib.offsetbox import DraggableOffsetBox
5152

5253
from matplotlib.container import ErrorbarContainer, BarContainer, StemContainer
54+
from matplotlib.text import Annotation, Text
5355
from . import legend_handler
5456

5557

@@ -565,7 +567,6 @@ def _set_loc(self, loc):
565567
# value of the find_offset.
566568
self._loc_real = loc
567569
self.stale = True
568-
self._legend_box.set_offset(self._findoffset)
569570

570571
def _get_loc(self):
571572
return self._loc_real
@@ -649,7 +650,10 @@ def _approx_text_height(self, renderer=None):
649650
update_func=legend_handler.update_from_first_child),
650651
tuple: legend_handler.HandlerTuple(),
651652
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()
653657
}
654658

655659
# (get|set|update)_default_handler_maps are public interfaces to
@@ -837,6 +841,7 @@ def _init_legend_box(self, handles, labels, markerfirst=True):
837841
children=[self._legend_title_box,
838842
self._legend_handle_box])
839843
self._legend_box.set_figure(self.figure)
844+
self._legend_box.set_offset(self._findoffset)
840845
self.texts = text_list
841846
self.legendHandles = handle_list
842847

@@ -1142,12 +1147,13 @@ def _get_legend_handles(axs, legend_handler_map=None):
11421147
handles_original = []
11431148
for ax in axs:
11441149
handles_original += (ax.lines + ax.patches +
1145-
ax.collections + ax.containers)
1150+
ax.collections + ax.containers + ax.texts)
11461151
# support parasite axes:
11471152
if hasattr(ax, 'parasites'):
11481153
for axx in ax.parasites:
11491154
handles_original += (axx.lines + axx.patches +
1150-
axx.collections + axx.containers)
1155+
axx.collections + axx.containers +
1156+
axx.texts)
11511157

11521158
handler_map = Legend.get_default_handler_map()
11531159

0 commit comments

Comments
 (0)