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

Skip to content

Commit 82b1c1b

Browse files
committed
Add pie container to Axes.containers list
1 parent 4ea67fe commit 82b1c1b

3 files changed

Lines changed: 12 additions & 0 deletions

File tree

lib/matplotlib/axes/_axes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3710,6 +3710,7 @@ def get_next_color():
37103710
theta1 = theta2
37113711

37123712
pc = PieContainer(slices, x, normalize)
3713+
self.add_container(pc)
37133714

37143715
if labeldistance is None:
37153716
# Insert an empty list of texts for backwards compatibility of the

lib/matplotlib/container.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ def __init__(self, wedges, values, normalize):
181181
self._texts = []
182182
self._values = values
183183
self._normalize = normalize
184+
self._remove_method = None
184185

185186
@property
186187
def texts(self):
@@ -214,11 +215,19 @@ def remove(self):
214215
for artist in cbook.flatten(artist_list):
215216
artist.remove()
216217

218+
if self._remove_method is not None:
219+
self._remove_method(self)
220+
217221
def __getitem__(self, key):
218222
# needed to support unpacking into a tuple for backward compatibility of the
219223
# Axes.pie return value
220224
return (self.wedges, *self._texts)[key]
221225

226+
def get_label(self):
227+
# needed for adding to the Axes.container list but we have no legend handler
228+
# so always return a string that legend will ignore
229+
return '_pie'
230+
222231

223232
class StemContainer(Container):
224233
"""

lib/matplotlib/tests/test_container.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,12 @@ def test_piecontainer_remove():
6161
ax.pie_label(pie, ['baz', 'qux'])
6262
assert len(ax.patches) == 2
6363
assert len(ax.texts) == 6
64+
assert pie in ax.containers
6465

6566
pie.remove()
6667
assert not ax.patches
6768
assert not ax.texts
69+
assert not ax.containers
6870

6971

7072
def test_piecontainer_unpack_backcompat():

0 commit comments

Comments
 (0)