Skip to content

Commit fbcaec5

Browse files
committed
ENH: Added remove methods for legends in figure and axes objects
1 parent 84e25db commit fbcaec5

File tree

2 files changed

+2
-0
lines changed

2 files changed

+2
-0
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,7 @@ def legend(self, *args, **kwargs):
509509
raise TypeError('Invalid arguments to legend.')
510510

511511
self.legend_ = mlegend.Legend(self, handles, labels, **kwargs)
512+
self.legend_._remove_method = lambda h: setattr(self, 'legend_', None)
512513
return self.legend_
513514

514515
def text(self, x, y, s, fontdict=None,

lib/matplotlib/figure.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,6 +1166,7 @@ def legend(self, handles, labels, *args, **kwargs):
11661166
"""
11671167
l = Legend(self, handles, labels, *args, **kwargs)
11681168
self.legends.append(l)
1169+
l._remove_method = lambda h: self.legends.remove(h)
11691170
return l
11701171

11711172
@docstring.dedent_interpd

0 commit comments

Comments
 (0)