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

Skip to content

Commit d17863f

Browse files
committed
MNT : remove code to handle callable legend handlers
Deprecated in #2442 / 9e0be95
1 parent 843e16f commit d17863f

3 files changed

Lines changed: 8 additions & 42 deletions

File tree

doc/api/api_changes/code_removal.rst

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@ Code Removal
33

44
Legend
55
------
6-
Removed handling of `loc` as a positional argument to `Legend`
6+
- Removed handling of `loc` as a positional argument to `Legend`
7+
8+
9+
Legend handlers
10+
~~~~~~~~~~~~~~~
11+
Remove code to allow legend handlers to be callable. They must now
12+
implement a method ``legend_artist``.
713

814

915
Axis

lib/matplotlib/legend.py

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@
3333

3434
from matplotlib import rcParams
3535
from matplotlib.artist import Artist, allow_rasterization
36-
from matplotlib.cbook import (is_string_like, iterable, silent_list, safezip,
37-
warn_deprecated)
36+
from matplotlib.cbook import (is_string_like, iterable, silent_list, safezip)
3837
from matplotlib.font_manager import FontProperties
3938
from matplotlib.lines import Line2D
4039
from matplotlib.patches import Patch, Rectangle, Shadow, FancyBboxPatch
@@ -647,17 +646,6 @@ def _init_legend_box(self, handles, labels, markerfirst=True):
647646
xdescent=0., ydescent=descent)
648647
handleboxes.append(handlebox)
649648

650-
# Deprecate the old behaviour of accepting callable
651-
# legend handlers in favour of the "legend_artist"
652-
# interface.
653-
if (not hasattr(handler, 'legend_artist') and
654-
callable(handler)):
655-
handler.legend_artist = handler.__call__
656-
warn_deprecated('1.4',
657-
('Legend handers must now implement a '
658-
'"legend_artist" method rather than '
659-
'being a callable.'))
660-
661649
# Create the artist for the legend which represents the
662650
# original artist/handle.
663651
handle_list.append(handler.legend_artist(self, orig_handle,

lib/matplotlib/tests/test_legend.py

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -170,34 +170,6 @@ def test_legend_remove():
170170

171171
class TestLegendFunction(object):
172172
# Tests the legend function on the Axes and pyplot.
173-
174-
@cleanup
175-
def test_old_legend_handler_interface(self):
176-
# Check the deprecated warning is created and that the appropriate
177-
# call to the legend handler is made.
178-
class AnyObject(object):
179-
pass
180-
181-
class AnyObjectHandler(object):
182-
def __call__(self, legend, orig_handle, fontsize, handlebox):
183-
x0, y0 = handlebox.xdescent, handlebox.ydescent
184-
width, height = handlebox.width, handlebox.height
185-
patch = mpatches.Rectangle([x0, y0], width, height, facecolor='red',
186-
edgecolor='black', hatch='xx', lw=3,
187-
transform=handlebox.get_transform())
188-
handlebox.add_artist(patch)
189-
return patch
190-
191-
with mock.patch('warnings.warn') as warn:
192-
plt.legend([None], ['My first handler'],
193-
handler_map={None: AnyObjectHandler()})
194-
195-
warn.assert_called_with('Legend handers must now implement a '
196-
'"legend_artist" method rather than '
197-
'being a callable.',
198-
MatplotlibDeprecationWarning,
199-
stacklevel=1)
200-
201173
@cleanup
202174
def test_legend_handle_label(self):
203175
lines = plt.plot(range(10))

0 commit comments

Comments
 (0)