Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Code removal #3992

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Feb 6, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
MNT : remove code to handle callable legend handlers
Deprecated in #2442 / 9e0be95
  • Loading branch information
tacaswell committed Jan 22, 2015
commit d17863faa64e49caca1cf74288486112ab22f34c
8 changes: 7 additions & 1 deletion 8 doc/api/api_changes/code_removal.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@ Code Removal

Legend
------
Removed handling of `loc` as a positional argument to `Legend`
- Removed handling of `loc` as a positional argument to `Legend`


Legend handlers
~~~~~~~~~~~~~~~
Remove code to allow legend handlers to be callable. They must now
implement a method ``legend_artist``.


Axis
Expand Down
14 changes: 1 addition & 13 deletions 14 lib/matplotlib/legend.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@

from matplotlib import rcParams
from matplotlib.artist import Artist, allow_rasterization
from matplotlib.cbook import (is_string_like, iterable, silent_list, safezip,
warn_deprecated)
from matplotlib.cbook import (is_string_like, iterable, silent_list, safezip)
from matplotlib.font_manager import FontProperties
from matplotlib.lines import Line2D
from matplotlib.patches import Patch, Rectangle, Shadow, FancyBboxPatch
Expand Down Expand Up @@ -647,17 +646,6 @@ def _init_legend_box(self, handles, labels, markerfirst=True):
xdescent=0., ydescent=descent)
handleboxes.append(handlebox)

# Deprecate the old behaviour of accepting callable
# legend handlers in favour of the "legend_artist"
# interface.
if (not hasattr(handler, 'legend_artist') and
callable(handler)):
handler.legend_artist = handler.__call__
warn_deprecated('1.4',
('Legend handers must now implement a '
'"legend_artist" method rather than '
'being a callable.'))

# Create the artist for the legend which represents the
# original artist/handle.
handle_list.append(handler.legend_artist(self, orig_handle,
Expand Down
28 changes: 0 additions & 28 deletions 28 lib/matplotlib/tests/test_legend.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,34 +170,6 @@ def test_legend_remove():

class TestLegendFunction(object):
# Tests the legend function on the Axes and pyplot.

@cleanup
def test_old_legend_handler_interface(self):
# Check the deprecated warning is created and that the appropriate
# call to the legend handler is made.
class AnyObject(object):
pass

class AnyObjectHandler(object):
def __call__(self, legend, orig_handle, fontsize, handlebox):
x0, y0 = handlebox.xdescent, handlebox.ydescent
width, height = handlebox.width, handlebox.height
patch = mpatches.Rectangle([x0, y0], width, height, facecolor='red',
edgecolor='black', hatch='xx', lw=3,
transform=handlebox.get_transform())
handlebox.add_artist(patch)
return patch

with mock.patch('warnings.warn') as warn:
plt.legend([None], ['My first handler'],
handler_map={None: AnyObjectHandler()})

warn.assert_called_with('Legend handers must now implement a '
'"legend_artist" method rather than '
'being a callable.',
MatplotlibDeprecationWarning,
stacklevel=1)

@cleanup
def test_legend_handle_label(self):
lines = plt.plot(range(10))
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.